Navigate to current user’s path in PowerShell

I guess everyone knows that you can find current logged-in user’s profile path using variable $env:USERPROFILE, which is one of the built in environmental variables in PowerShell. However, you can also choose to navigate to current user’s profile path using ‘~’ (without single quotes). So for an example would be:

PS data [07/11/2017 09:58:00]> pwd

Path
----
C:\data

PS data [07/11/2017 09:58:01]> cd ~
PS mogoyal[07/11/2017 09:58:05]> pwd

Path
----
C:\Users\mogoyal

However, unlike $env:userprofile, you can not use this in write-host to print out the value of the path.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s