Getting the user's Documents folder in Powershell

powershell-3.0, windows-server-2008-r2

Solution

try this:

[Environment]::GetFolderPath("MyDocuments")

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

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

Problem

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?

Original source

Related problems