4

I often re-install Windows on my PC, and store all my user files on a dedicated drive, say D:.

Every time I do this, I have to manually go to C:\Users\<username>\, right-click on every single folder (and some subfolders like AppData\Roaming\Microsoft\Windows\Start Menu\Programs) and change their location as shown below:

Folder Properties Dialog, Location Tab

To make this easier, I want to write a .bat or .ps1 script that does this automatically. Is there a built-in cmdlet that lets me do this?

0

There is no built in cmdlet to do this, as it is absolutely unsupported, and can break your modern applications. Read: Your start menu, cortana, and more. There is a registry key to redirect profiles, but I would not advise using it.

Reference the ProfilesDirectory key on MSDN, which does this as well. You put a path here, and it moves your profile there. Definitely not recommended, though. Read "Important usage notes"

https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-folderlocations-profilesdirectory

If you just want to back it up, you could use

copy-item C:\users\username\folder D:\users\username\folder\

This would copy all contents of the folder on C:\ to the folder on D:\ Do not copy appdata from your profile, you'll have a bad time when you re-import it.

| improve this answer | |
  • I don't think you are correct in saying this is unsupported. As I have shown in my question, Windows has built-in UI for this for some special folders. Of course, I can not change the location of my users appdata folder that easily, but for most folders in the user directory, this works perfectly fine. This has been a feature in Windows since at least Windows 7 if not Vista or even XP. – iFreilicht Jun 19 '17 at 8:40
  • You are correct that moving %appdata% is a bad idea. Microsoft has never officially supported the redirection of profiles as a whole. Redirecting your profile can break some or all of your modern applications due to the user-state installation not being valid for a new build if the machine is ever imaged. I would recommend mirroring out to a removable or separate drive I'd recommend McDonald's answer to you, but it looks like you're set on using the SHSetKnown function. Check the script before you apply it. It contains profile redirection, which will include %appdata%. – Charlie C Jun 22 '17 at 12:45
0

Is this what you're looking for? https://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell

It shows how to set locations for special folders, like documents, downloads etc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.