Monday, September 13, 2010

Storing a Directory Path with a Space and Using it in PowerShell

Step 1: Store the path in a variable like so
$7Zip = "C:\Program Files (x86)\7za.exe"

Step 2: Wrap the reference in the double quotes and precede with the call operator like so
ForEach-Object { &"$7Zip" a ($_.fullname -replace "txt", "zip") $_.fullname }

Step 3: Complain silently in your head about the time you wasted trying to figure that out.