December 22, 2024
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.

4 thoughts on “Copy files to Desktop (stored in OneDrive)

  1. This is a really good idea and it’s something I need but, I have 1 question. If I copied something to C\users\public\desktop, this would copy to all current users and all new users who logon to that PC.

    This looks like it finds all the current users and copy the file over to current users. IS there a way to copy to all the users and to all users going forward ?

    1. Hi, you can just use the Public environment variable which by default will point to C:\Users\Pbulic. Add the Desktop folder to it to get the public desktop folder which indeed counts for every user on the computer.

  2. thanks! very helpful article in a situation where I had to deploy a shortcut via powershell (using intune/mem)

    $desktoploc = ([Environment]::GetFolderPath(“Desktop”))
    $ShortcutFile = “$desktoploc\Quick Assist.lnk”

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.