Friday, July 28, 2017

Powershell List folder content, search by criteria, list files, delete, check existence, report

$ErrorActionPreference = "SilentlyContinue";
Stop-Transcript | out-null
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-logfiles-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
$criteria = Minidump*.dmp
Write-Host Step Delete MINIDUMP FILEs Start at $(get-date)
$mindump = gci c:\test1 -recurse -Include "$criteria"
if ($mindump -eq $null) {write-host *** No files found to delete ***} else {write-host List of files to delete:; $mindump | % {write-host $_}}
remove-item $mindump -force
$mindump | % {If(test-path $_){ write-host $_";File NOT DELETED"} else {write-host $_";File DELETED"}}

Write-Host Step Delete MINIDUMP FILEs Finished at $(get-date)
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213 –Message $text


Post a Comment