Question

Does anybody had a problem overwriting files with 7zip. I use this script:

    if ($name.Contains('something'))
 {
 Get-ChildItem \\server\load\$name | 
 % {
 & "C:\test\7z.exe" "x" "-aoa" "-y" $_.fullname "-o\\server\output"
   }
  }
else
{
"$name unknown"
}

Everything works fine when you delete files before triggering script, but it wont overwrite new files. I use -aoa for that, but maybe there is different switch for that? When i try to extract files on 7zip GUI and overwrite its fine also, so i guess it is not permission problem.

Thanks

Was it helpful?

Solution

Try using this:

&"C:\test\7z.exe" x -aoa -y "$_.fullname" -o"\\server\output"

The & is not very consistent with how it handles arguments, in my experience. Generally, though, you should assume that PowerShell doesn't strip quotes from arguments when you use &. You should only use quotes when the program you're calling needs them in it's own arguments. In my script which archives IIS logs, I use this:

&"$7Zip" a "$ArchiveFile" "$FullLogPath\$LogFileSpec" -mx=9 -mmt=on

The variables are just path or file names. The quotes are there simply because path and file names can have spaces in them.

The way I usually figure it out is by Write-Host the string that & is going to call, then copy and pasting it into a cmd.exe shell window

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top