Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Last active April 10, 2024 17:19
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/7b0f2ef6bba261edf43159b8dcc02052 to your computer and use it in GitHub Desktop.
Save joerodgers/7b0f2ef6bba261edf43159b8dcc02052 to your computer and use it in GitHub Desktop.
Exports the data from the hidden tenant admin site collection aggregated data to csv.
#requires -Modules PnP.PowerShell
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
$tenant = $env:TENANT
$clientId = $env:CLIENTID
$thumbprint = $env:THUMBPRINT
$outputPath = $env:LOGDIRECTORY
Connect-PnPOnline -Url "https://$tenant-admin.sharepoint.com" -ClientId $clientId -Thumbprint $thumbprint -Tenant "$tenant.onmicrosoft.com"
# DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS
$list = Get-PnpList -Identity "DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS" -Includes Fields
$fields = "AllowGuestUserSignIn", "CreatedBy", "DeletedBy", "ExternalSharing", "FileViewedOrEdited", "GroupId", "HubSiteId", "Initiator", "IsGroupConnected", "LastActivityOn", "NumOfFiles", "PageViews", "PagesVisited", "SensitivityLabel", "SiteCreationSource", "SiteId", "SiteUrl", "SiteOwnerEmail", "SiteOwnerName", "State", "StorageQuota", "StorageUsed", "StorageUsedPercentage", "TemplateName", "TimeCreated", "TimeDeleted", "Title" | SELECT -Unique
$items = Get-PnPListItem -List $list -Fields $fields
$results = @()
foreach( $item in $items )
{
$result = [PSCustomObject] @{}
foreach( $field in $fields )
{
$result | Add-Member -MemberType NoteProperty -Name $field -Value $item.FieldValues[$field]
}
$results += $result
}
$path = Join-Path -Path $outputPath -ChildPath "DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS.csv"
$results | Export-Csv -Path $path -NoTypeInformation
# DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGATED_SITECOLLECTIONS
$list = Get-PnpList -Identity "DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGATED_SITECOLLECTIONS"
$fields = "ConditionalAccessPolicy", "CreatedBy", "DeletedBy", "Initiator", "IsRestorable", "LastListActivityOn", "LastItemModifiedDate", "LastWebActivityOn", "NumOfFiles", "ShareByEmailEnabled", "ShareByLinkEnabled", "SiteId", "SiteOwnerEmail", "SiteOwnerName", "SiteUrl", "State", "StorageQuota", "StorageUsed", "TemplateId", "TemplateName", "TimeCreated", "TimeDeleted", "Title", "StorageUsedPercentage", "SensitivityLabel" | SELECT -Unique
$items = Get-PnPListItem -List $list -Fields $fields
$results = @()
foreach( $item in $items )
{
$result = [PSCustomObject] @{}
foreach( $field in $fields )
{
$result | Add-Member -MemberType NoteProperty -Name $field -Value $item.FieldValues[$field]
}
$results += $result
}
$path = Join-Path -Path $outputPath -ChildPath "DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGATED_SITECOLLECTIONS.csv"
$results | Export-Csv -Path $path -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment