Created
November 14, 2019 21:40
-
-
Save joerodgers/933eb3e93d28302b9c7955820f54df83 to your computer and use it in GitHub Desktop.
Tries to open all 6 byte files in a site collection and reports if the opening was successful or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell | |
function Get-FilesThatWillNotOpen | |
{ | |
[cmdletbinding()] | |
param | |
( | |
[parameter(Mandatory=$true)][Microsoft.SharePoint.SPSite]$Site | |
) | |
begin | |
{ | |
} | |
process | |
{ | |
$webs = $Site | Get-SPWeb -Limit All | |
foreach( $web in $webs ) | |
{ | |
$libraries = $web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary) | |
foreach( $library in $libraries ) | |
{ | |
$query = New-Object Microsoft.SharePoint.SPQuery | |
$query.ViewXml = "<View Scope='RecursiveAll'> | |
<Query> | |
<Where> | |
<Eq> | |
<FieldRef Name='File_x0020_Size' /> | |
<Value Type='Integer'>6</Value> | |
</Eq> | |
</Where> | |
</Query> | |
<ViewFields/> | |
<RowLimit Paged='TRUE'>5000</RowLimit> | |
</View>" | |
do | |
{ | |
$batch = $Library.GetItems($query) | |
$query.ListItemCollectionPosition = $batch.ListItemCollectionPosition | |
foreach( $item in $batch ) | |
{ | |
$corrupt = $true | |
try | |
{ | |
$item.File.OpenBinary() | Out-Null | |
$corrupt = $false | |
} | |
catch | |
{ | |
$corrupt = $true | |
} | |
[PSCustomObject] @{ | |
Site = $item.ParentList.ParentWeb.Site.Url | |
Web = $item.ParentList.ParentWeb.Url | |
List = $item.ParentList.Title | |
FileName = $item.File.Name | |
FilePath = $item.File.ServerRelativeUrl | |
IsShortcut = $item.File.Properties["evsp_Shortcut"] | |
Corrupt = $corrupt | |
} | |
} | |
} | |
while($batch.ListItemCollectionPosition -ne $null) | |
} | |
} | |
} | |
end | |
{ | |
} | |
} | |
$site = Get-SPSIte -Identity "https://sharepoint.2016.contoso.com/sites/teamsite" | |
Get-FilesThatWillNotOpen -Site $site -Verbose | Export-Csv -Path "FilesThatWillNotOpen_$(Get-Date -Format FileDate).csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment