Saturday, January 13, 2007

Going Home in PowerShell

In PowerShell, the "~" symbol is used as your home folder, which you can use in constructing file paths as follows:

PSH [D:\foo]: cd ~
PSH [D:\Users\tfl]:
cd \foo
PSH [D:\foo]: ls ~

Directory: Microsoft.PowerShell.Core\FileSystem::D:\Users\tfl

Mode LastWriteTime Length Name
---- ------------- ------ ----
d-r-- 10/12/2006 11:52 Contacts
...

PSH [D:\foo]: ls ~\links

Directory: Microsoft.PowerShell.Core\FileSystem::D:\Users\tfl\links

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 25/11/2006 20:02 376 Documents.lnk
-a--- 25/11/2006 20:02 364 Music.lnk
-a--- 25/11/2006 20:02 373 Pictures.lnk
...

 

By default, PowerShell sets ~  to <systemdrive>:\users\<current user>. I prefer on my laptop to have a home folder set to D:\foo. So to change where PowerShell points, you just need to update the filesystem provider as follows:

PSH [D:\foo]: $provider=get-psprovider filesystem
PSH [D:\foo]:
$provider.home="D:\foo"
PSH [D:\foo]: cd \
PSH [D:\]: cd ~
PSH [D:\foo]:

 

Technorati tags: ,

No comments: