A couple of notes about the script:
- By default it will not delete anything, just list the urls that contain the $document argument.
- The $document argument is matched with like as it's matching urls, so be careful that it doesn't delete more documents than you want.
param
(
[string]$url = "https://sp.dev.local",
[string]$document = "Welcome"
[bool]$delete = false
)
$site = Get-SPSite $url
foreach($web in $site.AllWebs) {
foreach($list in $web.Lists) {
if($list.BaseType -eq "DocumentLibrary") {
foreach($item in $list.Items){
if($item.url -like "*$document*")
{
if($delete)
{
Write-Host "Deleting $item.url"
$item.File.Delete()
}
else
{
Write-Host "$item.url"
}
}
}
}
}
}
No comments:
Post a Comment