$site = Get-SPSite "http://yourwebapplication/sitecollection" foreach ($web in $site.AllWebs) { $Libraries = $web.Lists | where {$_.BaseType -eq "DocumentLibrary"} foreach ($library in $Libraries) { Write-Output "Getting files from $($library.Title)" $Files = $library.Items | where {$_.FileSystemObjectType -eq "File"} foreach ($file in $Files) { Write-Output "Deleting file $($file.Name)..." $file.Delete() } # foreach file } # foreach library } # foreach web
What if you want to delete only specific MS Office like docx or pptx?
$site = Get-SPSite "http://collaboration-dev/team" foreach ($web in $site.AllWebs) { $Libraries = $web.Lists | where {$_.BaseType -eq "DocumentLibrary"} foreach ($library in $Libraries) { Write-Output "Getting files from $($library.Title)" $Files = $library.Items | where {$_.FileSystemObjectType -eq "File" -And ($_.File -Like "*.docx" -Or $_.File -Like "*.ppt" -Or $_.File -Like "*.pptx")} foreach ($file in $Files) { Write-Output "Deleting file $($file.Name)..." $file.Delete() } # foreach file } # foreach library } # foreach web
Source:
No comments:
Post a Comment