Find a users home directory in Powershell

For one of my projects I needed to find a users home directory and copy something there. I was using the $home Powershell variable but this seemed to cause issues with Windows 7 where $home seemed to point to a users mapped H:\ drive. Therefore I needed to find a way of finding the folder in a more reliable way. Windows has a built in %userprofile% variable and to access this from Powershell you omit the % and add the prefix $env therefore you can get the location of a users home directory by using:


On Windows XP this gives you: C:\Documents and Settings\%username%

On Windows 7: C:\Users\%username%

Jason Edwards

  • excellent post. fascinating reading. i’d be happy to have you submit your article links for any future postings such as these you feel might be useful for your readership.

  • Grateful HumanBeing

    Thanks.. just what I needed. +1 (though I wouldn’t say it was fascinating reading..)