Synchronizing Current Folder

by Jun 20, 2012

PowerShell allows its own current path to differ from what Windows thinks is the current path:

[IO.Path]::GetFullPath('.')
cd $env:windir
Get-Location
[IO.Path]::GetFullPath('.') 

So, whenever you want to use one of the .NET Framework methods from IO.Path, you need to sync the current location like this:

[IO.Path]::GetFullPath('.')
cd $env:windir
[IO.Directory]::SetCurrentDirectory((Get-Location -PSProvider FileSystem).ProviderPath)
Get-Location
[IO.Path]::GetFullPath('.')

Twitter This Tip! ReTweet this Tip!