Created
April 1, 2024 14:04
-
-
Save joerodgers/5a2648b63d81a6bab6ceaad2a7a6be55 to your computer and use it in GitHub Desktop.
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
#requires -modules "PnP.PowerShell" | |
function Test-ListItemPath | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[parameter(mandatory=$true)] | |
[string] | |
$ItemServerRelativeUrl | |
) | |
begin | |
{ | |
} | |
process | |
{ | |
try | |
{ | |
$null = Invoke-PnPSPRestMethod -Method Get -Url "/_api/web/GetFileByServerRelativeUrl('$ItemServerRelativeUrl')" | |
return $true | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
$null = Invoke-PnPSPRestMethod -Method Get -Url "/_api/web/GetFolderByServerRelativeUrl('$ItemServerRelativeUrl')" | |
return $true | |
} | |
catch | |
{ | |
} | |
return $false | |
} | |
end | |
{ | |
} | |
} | |
Connect-PnPOnline ` | |
-Url "https://$env:O365_TENANT-admin.sharepoint.com" ` | |
-ClientId $env:O365_CLIENTID ` | |
-Thumbprint $env:O365_THUMBPRINT ` | |
-Tenant $env:O365_TENANTID ` | |
-ErrorAction Stop | |
$rows = Import-Csv -Path "C:\_temp\SharePoint_EveryoneOrEEEUSharedItems_20240329T1418351853.csv" | |
foreach( $row in $rows ) | |
{ | |
try | |
{ | |
# add new "exists" row to object | |
if( $row.psobject.Properties.Name -notcontains "Exists" ) | |
{ | |
$row | Add-Member -MemberType NoteProperty -Name "Exists" -Value "" -ErrorAction Stop | |
} | |
# skip anyting that is not a doc lib or a wiki lib | |
if( $row.ContentClass -ne "STS_ListItem_DocumentLibrary" -and $row.ContentClass -ne "STS_ListItem_WebPageLibrary" ) | |
{ | |
continue | |
} | |
# skip anything with a blank webUrl | |
if( -not $row.SPWebUrl ) | |
{ | |
continue | |
} | |
$connection = Get-PnpConnection -ErrorAction Stop | |
if( $connection.Url -ne $row.SPWebUrl ) | |
{ | |
Write-Host "[$(Get-Date)] - Connecting to $($row.SPWebUrl)" | |
Connect-PnPOnline ` | |
-Url $row.SPWebUrl ` | |
-ClientId $connection.ClientId ` | |
-Thumbprint $connection.Certificate.Thumbprint ` | |
-Tenant $connection.Tenant ` | |
-ErrorAction Stop | |
} | |
$uri = [System.Uri]$row.Path | |
Write-Host "[$(Get-Date)] - Testing Item: $($uri.AbsolutePath)" | |
$exists = Test-ListItemPath -ItemServerRelativeUrl $uri.AbsolutePath -ErrorAction Stop | |
if( $row.psobject.Properties.Name -notcontains "Exists" ) | |
{ | |
$row | Add-Member -MemberType NoteProperty -Name "Exists" -Value $exists -ErrorAction Stop | |
} | |
else | |
{ | |
$row.Exists = $exists | |
} | |
} | |
catch | |
{ | |
Write-Host "Failed to process path: $($row.Path). Error: $_ " -ForegroundColor Red | |
} | |
} | |
$rows | Export-Csv -path "C:\_temp\SharePoint_EveryoneOrEEEUSharedItems_20240329T1418351853_EXISTS.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment