Tarek EZZAT
Tarek EZZAT

Reputation: 353

Windows Powershell Environment Variables

I tried but did not find an answer :

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

Upvotes: 0

Views: 232

Answers (3)

wasif
wasif

Reputation: 15528

Try this:

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

Upvotes: 0

js2010
js2010

Reputation: 27626

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

Upvotes: 1

Jeff Zeitlin
Jeff Zeitlin

Reputation: 10819

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

Upvotes: 1

Related Questions