Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FolderItem.InvokeVerb("Delete") without confirmation

Tags:

powershell

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?

like image 970
Envilogger Avatar asked May 01 '26 16:05

Envilogger


1 Answers

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.

like image 103
Envilogger Avatar answered May 04 '26 10:05

Envilogger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!