windows-server-2008-r2powershell-3.0

Getting the user's Documents folder in Powershell


I want to use a PowerShell script to automate tasks related to the user when the user logs in.

Sometimes a user will have moved his Documents folder from the default location. How can I determine the location of the user's Documents folder in PowerShell?


Solution

  • try this:

    [Environment]::GetFolderPath("MyDocuments")
    

    When supplying it to a command, make sure to place it into parentheses:

    cd ([Environment]::GetFolderPath("MyDocuments"))