Change location of user folders through cmd or PowerShell?












2















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 AppDataRoamingMicrosoftWindowsStart MenuPrograms) 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?










share|improve this question


















  • 1





    See this Q&A at StackOverflow

    – LotPings
    Jun 15 '17 at 22:03











  • Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

    – Pimp Juice IT
    Jun 16 '17 at 1:59











  • @McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

    – iFreilicht
    Jun 19 '17 at 8:42











  • Those can be easily done with registry. I.e. reg command.

    – Biswapriyo
    Jun 19 '17 at 12:44
















2















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 AppDataRoamingMicrosoftWindowsStart MenuPrograms) 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?










share|improve this question


















  • 1





    See this Q&A at StackOverflow

    – LotPings
    Jun 15 '17 at 22:03











  • Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

    – Pimp Juice IT
    Jun 16 '17 at 1:59











  • @McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

    – iFreilicht
    Jun 19 '17 at 8:42











  • Those can be easily done with registry. I.e. reg command.

    – Biswapriyo
    Jun 19 '17 at 12:44














2












2








2


1






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 AppDataRoamingMicrosoftWindowsStart MenuPrograms) 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?










share|improve this question














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 AppDataRoamingMicrosoftWindowsStart MenuPrograms) 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?







windows windows-10 command-line powershell cmd.exe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 15 '17 at 20:26









iFreilichtiFreilicht

1811212




1811212








  • 1





    See this Q&A at StackOverflow

    – LotPings
    Jun 15 '17 at 22:03











  • Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

    – Pimp Juice IT
    Jun 16 '17 at 1:59











  • @McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

    – iFreilicht
    Jun 19 '17 at 8:42











  • Those can be easily done with registry. I.e. reg command.

    – Biswapriyo
    Jun 19 '17 at 12:44














  • 1





    See this Q&A at StackOverflow

    – LotPings
    Jun 15 '17 at 22:03











  • Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

    – Pimp Juice IT
    Jun 16 '17 at 1:59











  • @McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

    – iFreilicht
    Jun 19 '17 at 8:42











  • Those can be easily done with registry. I.e. reg command.

    – Biswapriyo
    Jun 19 '17 at 12:44








1




1





See this Q&A at StackOverflow

– LotPings
Jun 15 '17 at 22:03





See this Q&A at StackOverflow

– LotPings
Jun 15 '17 at 22:03













Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

– Pimp Juice IT
Jun 16 '17 at 1:59





Also see: social.technet.microsoft.com/Forums/scriptcenter/en-US/… and helgeklein.com/blog/2015/02/… for some more detail about this task.

– Pimp Juice IT
Jun 16 '17 at 1:59













@McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

– iFreilicht
Jun 19 '17 at 8:42





@McDonald's I think that script is much less safe as it purely modifies the registry entries. The answer LotPings linked is relying on API that is supported and maintained.

– iFreilicht
Jun 19 '17 at 8:42













Those can be easily done with registry. I.e. reg command.

– Biswapriyo
Jun 19 '17 at 12:44





Those can be easily done with registry. I.e. reg command.

– Biswapriyo
Jun 19 '17 at 12:44










2 Answers
2






active

oldest

votes


















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:usersusernamefolder D:usersusernamefolder



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.






share|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.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1219716%2fchange-location-of-user-folders-through-cmd-or-powershell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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:usersusernamefolder D:usersusernamefolder



    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.






    share|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














    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:usersusernamefolder D:usersusernamefolder



    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.






    share|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












    0








    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:usersusernamefolder D:usersusernamefolder



    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.






    share|improve this answer













    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:usersusernamefolder D:usersusernamefolder



    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 16 '17 at 19:19









    Charlie CCharlie C

    863




    863













    • 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



















    • 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

















    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





    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





    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.






    share|improve this answer




























      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.






      share|improve this answer


























        0












        0








        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.






        share|improve this answer













        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|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 5 '17 at 8:44









        Tommy BråthenTommy Bråthen

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1219716%2fchange-location-of-user-folders-through-cmd-or-powershell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            Puebla de Zaragoza

            Musa