0

I tried but did not find an answer :

How do I get the current user home in Windows PowerShell?

3 Answers 3

1

System variables (those that you would address in Batch as %varname%) are accessible in PowerShell as $env:varname. You can list the system variables that are visible to your PowerShell session with Get-ChildItem -Path Env:.

Sign up to request clarification or add additional context in comments.

Comments

1

In Windows, it looks like $env:userprofile or $env:homepath without the drive.

dir env: | where value -match admin


Name                           Value
----                           -----
APPDATA                        C:\Users\admin\AppData\Roaming
HOMEPATH                       \Users\admin
LOCALAPPDATA                   C:\Users\admin\AppData\Local
OneDrive                       C:\Users\admin\OneDrive
Path                           C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Wind...
PSModulePath                   C:\Users\admin\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerSh...
TEMP                           C:\Users\admin\AppData\Local\Temp
TMP                            C:\Users\admin\AppData\Local\Temp
USERNAME                       admin
USERPROFILE                    C:\Users\admin

Comments

0

Try this:

[Environment]::ExpandEnvironmentVariables("%UserProfile%")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.