I'm trying to write a tool that will automatically archivate old log files on server and delete too old files from archive. And there are problem. I need to delete single file from .ZIP archive with powershell, so I do:
$testFile = "C:\test_logs\FirstEntry.zip"
$sh = New-Object -com shell.application
$zip = $sh.NameSpace($testFile)
$item = $zip.Items() | Select-Object -index 3
$item.InvokeVerb("Delete")
But I receive confirmation window when trying to delete file this way. Is it possible to delete file with InvokeVerb(ex) without confirmation? Or any other way to do it with powershell?
The easiest way I found is:
$tmp_dir = $env:Temp + "\log_archivation_temp\"
$sh = New-Object -com shell.application
$tmp = $sh.NameSpace($tmp_dir)
$tmp.MoveHere($item.Path)
Remove-Item $tmp_dir
So I just move old files from archive to temporary folder, then delete it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With