Skip to content

theknoxtech/Find-OneDrive-Shortcuts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Find-OneDriveShortcuts.ps1 PowerShell Script

Author: Jon Witherspoon Version: 1.0.0 Date: 2025-02-20

πŸ“œ Overview

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.

βš™οΈ Prerequisites

  • 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).

πŸš€ Installation & Setup

  1. Download: Place the Find-OneDriveShortcuts.ps1 script in a directory on your local machine.

  2. 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"

πŸ’‘ Usage

To execute the script, open a PowerShell terminal, navigate to the script's directory, and run the command.

Parameters

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.

✨ Examples

Example 1: List Shortcuts in the Console

This command runs the script and displays the full paths of all identified OneDrive shortcuts directly in the PowerShell window.

.\Find-OneDriveShortcuts.ps1

Expected Output:

C:\Users\JohnDoe\OneDrive - CompanyName\Shortcut Folder 1
C:\Users\JohnDoe\OneDrive - CompanyName\Shared Documents - Project Alpha

Example 2: Save Shortcut List to a File

This command runs the script and saves the output to a text file in the same directory where the script was run.

.\Find-OneDriveShortcuts.ps1 -SaveToFile

Expected Output:

File Saved to C:\Path\To\Your\Script\OneDriveShortcuts.txt

πŸ”§ Code Breakdown

The script operates on a simple but clever principle:

  1. 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.

  2. Check desktop.ini: For each folder, it checks for the existence of a hidden desktop.ini file. This file is used by Windows to store folder customization settings.

  3. Identify Icon Index: When a folder is a OneDrive shortcut, its desktop.ini file 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.

  4. 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 -SaveToFile switch was used.

⚠️ Troubleshooting

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.

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page for this project to see how you can help.

πŸ“„ License

This project is unlicensed and free to use.

About

Repo for script to find OneDrive Shortcuts

Resources

Stars

Watchers

Forks

Contributors