Skip to content

Instantly share code, notes, and snippets.

@Jackbennett
Forked from anonymous/Remove.ps1
Last active February 7, 2017 10:55
Show Gist options
  • Save Jackbennett/9ccacb9182ebd9554f20958462d2e984 to your computer and use it in GitHub Desktop.
Save Jackbennett/9ccacb9182ebd9554f20958462d2e984 to your computer and use it in GitHub Desktop.
#Remove-MailQueueObjects.ps1
Param(
$Path = "D:\tst",
$pattern = "TextString",
$filter = "*.eml"
}
Get-ChildItem -Recurse -Path $Path -File -Filter $filter |
where {
get-content $psitem.fullname -ReadCount 0 |
select-string $pattern -Context 0,1
} |
foreach {
Remove-Item $psitem -WhatIf
Remove-Item "$(join-path $psitem.Directory $psitem.BaseName).metadata" -whatif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment