Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created November 14, 2019 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/933eb3e93d28302b9c7955820f54df83 to your computer and use it in GitHub Desktop.
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.
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