Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2017 10:10
Show Gist options
  • Save anonymous/93a524a03bfa5e7461854a5387dc1014 to your computer and use it in GitHub Desktop.
Save anonymous/93a524a03bfa5e7461854a5387dc1014 to your computer and use it in GitHub Desktop.
#Remove-MailQueueObjects.ps1
$Path = "D:\tst"
$AllFiles = New-Object System.Collections.ArrayList
$AllFiles = Get-ChildItem -Recurse -Path $Path -File -verbose -Filter "*.eml"
$AllFiles.Count
While(($AllFiles | Select-Object -Last 10).Count -gt 0){
$Scope = $AllFiles | Select-Object -Last 100
Foreach($File in $Scope){
$FileContent = Get-Content -Path $File.FullName
if($FileContent.Contains("TextString")){
$File.FullName | Remove-Item -Force
"$($File.Directory)\$($File.BaseName).metadata" | Remove-Item -Force
}
$AllFiles.Remove($File)
}
$Scope.Count
$AllFiles.Count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment