Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joerodgers/181e0f498cc58eb73efa0194b4c3bc6b to your computer and use it in GitHub Desktop.
Save joerodgers/181e0f498cc58eb73efa0194b4c3bc6b to your computer and use it in GitHub Desktop.
Fills in the missing Site Url column value in the SharePointSiteUsageDetail report.
#requires -module "PnP.PowerShell"
# SharePoint > Application > Sites.FullControl.All
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\SharePointSiteUsageDetail6_3_2024 2_54_05 PM.csv"
foreach( $row in $rows )
{
try
{
$siteId = $row.'Site Id'
Write-Host "Processing site: $siteId"
if( [string]::IsNullOrWhiteSpace( $row.'Site URL' ) )
{
$response = Invoke-PnPSPRestMethod `
-Method GET `
-Url "/_api/Microsoft.Online.SharePoint.TenantAdministration.Tenant/sites('$siteId')"
$row.'Site URL' = $response.Url
}
}
catch
{
Write-Host "Failed to lookup site: $siteId. Error: $_" -ForegroundColor Red
}
}
$rows | Export-Csv -Path "C:\_temp\SharePointSiteUsageDetail6_3_2024 2_54_05 PM.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment