Peace For All

October 18, 2011

Beware of the Current Directory when using PowerShell Remoting!

Filed under: PowerShell, Programming, technology — Tags: , , , , — Devlin Bentley @ 2:04 pm

Are your files appearing in strange places? Or maybe not appearing at all? Does everything work when run locally, but when remoting all of a sudden things work a bit differently?

Be aware that when using PowerShell remoting that your working directory may not be what you expect!

Create a simple test script that writes out the value of Get-Location to a log file at anĀ absolute path. Run this script remotely to figure out what your actual default location is!

At the top of your scripts it may be a good idea to use Set-Location to make sure your current working directory is what you think it is. This is especially true if you try to access files relative to your script’s location. (This is good advice anyway!)

Also note that PowerShell tracks its current working directory differently than Windows does. A really good explanation of this exists at http://huddledmasses.org/powershell-power-user-tips-current-directory/

 

Blog at WordPress.com.