Change location of user folders through cmd or PowerShell?

13,471

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.

Share:
13,471

Related videos on Youtube

iFreilicht
Author by

iFreilicht

Updated on September 18, 2022

Comments

  • iFreilicht
    iFreilicht over 1 year

    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?

  • iFreilicht
    iFreilicht almost 7 years
    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.
  • Charlie C
    Charlie C almost 7 years
    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%.
  • JW0914
    JW0914 over 3 years
    User data folders are moveable and fully supported by Windows (see Properties - Location tab), making this answer factually inaccurate. The purpose of moving user data directories is not to backup their contents, but to separate them from the C: partition for a wide variety of reasons (shrinking the C: partition, as the maximum size required then becomes <300GB; ensuring data remains separate from the OS partition, allowing for more efficient backup and restore of the OS partition; etc.)