Share via


CMD line moving "LOCATION" of users profile FOLDERS

Question

Monday, July 24, 2017 3:30 PM

As part of my daily job we change the location of users profile folders (desktop, downloads, music...etc) to their one drive. The way do this is by going in to file explorer and clicking on each folder induvidually then changing the location on the location tab. Is there a way to do this from the command line so that we could build a batch file to move it like

mv "%userprofile%\Music" "%userprofile%\OneDrive\Music"

This doesn't work but you see what I am getting at.

Thanks for your help

All replies (5)

Monday, July 24, 2017 4:18 PM

Have you tried Move-item command in PowerShell?

https://technet.microsoft.com/en-us/library/ee176910.aspx


Monday, July 24, 2017 4:49 PM

If you on a domain you can do folder redirection with GPO. More info here: https://technet.microsoft.com/en-us/library/cc732275(v=ws.11).aspx

Otherwise, look in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders.

In there you'll find registry values that define where each folder is located. Changing these will take effect from the next login, or (if just changing where the folders are within the user's profile), you might be able to make changes to the default user profile and have them come out right in the first place.

Making registry changes in a script can be done with reg.exe, or presumably with powershell.


Monday, July 24, 2017 5:39 PM

this would be just a normal move, while what I am really looking for is a change of location


Monday, July 24, 2017 5:40 PM

hmmmm can you make registry changes from the command line?


Monday, July 24, 2017 5:52 PM

In a batch file:

%systemroot%\system32\reg.exe add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop /t REG_EXPAND_SZ /d "%%UserProfile%%\Desktop"

NB, the double % thing is so that the variable isn't expanded when the batch file processes it, resulting in %userprofile% ending up in the registry. i.e. so that the value is set to "%userprofile%\Desktop", not "C:\Users\UserName\Desktop".