My scripts runs an external command without any issue:
$Target= "X:\Backup 2017-12-27.7z"
Write-Host "Compressing as $Target..."
& "C:\Program Files\7-Zip\7z.exe" a "$Target" @C:\Webs\Scripts\include.txt -w
But it totally breaks when I add further switches:
$Target= "X:\Backup 2017-12-27.7z"
Write-Host "Compressing as $Target..."
& "C:\Program Files\7-Zip\7z.exe" a "$Target" -spf -i@C:\Webs\Scripts\include.txt -x@C:\Webs\Scripts\exclude.txt -w
7z.exe : ERROR: X:\Backup 2017-12-27.7z At C:\Webs\Scripts\backup.ps1:50 char:1 + & "C:\Program Files\7-Zip\7z.exe" a "$Target" -spf -i@C:\Webs\Scripts\include.t ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (ERROR: X:\Backup 2017-12-27.7z:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError X:\Backup 2017-12-27.7z Open ERROR: Can not open the file as [7z] archive ERRORS: Headers Error System ERROR: Incorrect function.
The command runs fine from cmd. What PowerShell syntax am I breaking and how do I fix it?
EchoArgsparses the command nicely. As a wild guess, what happens if you use an underscore instead of a space?$Target= "X:\Backup_2017-12-27.7z"?& $command $p1 $p2 $p3 $p4. This should work, I can't explain why, could be to do with how PS interprets all the syntax