December 6, 2021
PowerShell Copy-Item

Copy files to Desktop (stored in OneDrive)

If you are an administrator then sometimes you need to copy some files to users’ Desktop folder living in Onedrive. Or actually any “special” folder, like Favorites, My Documents, StartUp, etc.
This always used to be %USERPROFILE%\Desktop and any file you copied there would show up on the user’s desktop. However, with more and more people using OneDrive or OneDrive for Business something changes.

See this article on Microsoft’s website on how to move these folders to Onedrive.

Whenever the special folders are stored in OneDrive, the good-old %USERPROFILE%\Desktop folder is no longer working. This folder still exists and usually points to C:\Users\<Username>\Desktop, as %USERPROFILE% is pointing to C:\Users\<Username>, however if there are any files to begin with, those files will not be shown on the user’s desktop. Nor will any new file or shortcut you copy to that same location.

The actual folder location is not so predictable anymore when it lives in Onedrive.
Sure, with the normal OneDrive (the consumer version) this would most likely be C:\Users\<Username>\OneDrive\Desktop or %USERPROFILE%\OneDrive\Desktop, but with OneDrive for Business, the name of the OneDrive folder includes the Microsoft 365 tenant name. And since users can have a consumer OneDrive folder as wel as multiple OneDrive for Business folders there really is no “default” location anymore.

By using PowerShell you can still copy files to the actual desktop folder pretty easily. This is because PowerShell has access to the .NET environment variables pointing to the actual special folders. To copy a shortcut from C:\Temp to the Desktop you can use the following PowerShell command.

Copy-Item "C:\Temp\Application.lnk" -Destination ([Environment]::GetFolderPath("Desktop"))

The actual full-length location is of this location is:

[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)

In my next article I will explain how to copy a complete folder structure from one location to another with PowerShell. That includes every subdirectory and every file in it.

One thought on “Copy files to Desktop (stored in OneDrive)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.