Author: Jon Witherspoon Version: 1.0.0 Date: 2025-02-20
This script identifies all folders within your local OneDrive directory that are "Shortcuts" created using the "Add Shortcut to OneDrive" feature in a web browser. These shortcuts look like regular folders but are pointers to other locations in SharePoint or another user's OneDrive, and this script provides a simple way to list them.
-
PowerShell Version: 5.1 or higher.
-
OneDrive: The OneDrive for Business sync client must be installed and configured, with the user's files syncing to the default location (
$env:OneDrive).
-
Download: Place the
Find-OneDriveShortcuts.ps1script in a directory on your local machine. -
Unblock File (Optional): If you downloaded the script from the internet, you may need to unblock it. Open a PowerShell terminal and run:
Unblock-File -Path ".\Find-OneDriveShortcuts.ps1"
To execute the script, open a PowerShell terminal, navigate to the script's directory, and run the command.
| Parameter | Type | Required | Description |
|---|---|---|---|
-SaveToFile |
Switch |
No | If present, saves the list of shortcut paths to a file named OneDriveShortcuts.txt in the current directory. |
This command runs the script and displays the full paths of all identified OneDrive shortcuts directly in the PowerShell window.
.\Find-OneDriveShortcuts.ps1Expected Output:
C:\Users\JohnDoe\OneDrive - CompanyName\Shortcut Folder 1
C:\Users\JohnDoe\OneDrive - CompanyName\Shared Documents - Project AlphaThis command runs the script and saves the output to a text file in the same directory where the script was run.
.\Find-OneDriveShortcuts.ps1 -SaveToFileExpected Output:
File Saved to C:\Path\To\Your\Script\OneDriveShortcuts.txtThe script operates on a simple but clever principle:
-
Scan OneDrive: It begins by getting a recursive list of all directories within the user's OneDrive folder, identified by the environment variable
$env:OneDrive. -
Check
desktop.ini: For each folder, it checks for the existence of a hiddendesktop.inifile. This file is used by Windows to store folder customization settings. -
Identify Icon Index: When a folder is a OneDrive shortcut, its
desktop.inifile contains a specific line (IconResource=...OneDrive.exe,[index]) that points to an icon within the OneDrive executable. The script checks if the icon index number in this file matches a predefined list of numbers known to be associated with OneDrive shortcuts. -
Collect and Output: If a match is found, the folder's path is added to a list. Finally, this list is either displayed on the console or written to a file, depending on whether the
-SaveToFileswitch was used.
| Issue | Cause | Resolution |
|---|---|---|
| Script returns no results, but shortcuts exist. | The OneDrive folder is not in the default location pointed to by $env:OneDrive. |
This script is hardcoded to use the default environment variable. You would need to modify the script to point to your custom OneDrive path. |
Access Denied error when reading desktop.ini. |
The user running the script does not have read permissions for a specific folder in their OneDrive. | Ensure you are running the script as the logged-in user and that you have permissions to access all subfolders within your OneDrive. |
Contributions, issues, and feature requests are welcome! Feel free to check the issues page for this project to see how you can help.
This project is unlicensed and free to use.