|
#requires -modules "Pnp.PowerShell" |
|
|
|
Connect-PnPOnline -Url "https://$env:CDX_TENANT-admin.sharepoint.com" ` |
|
-ClientId $env:CDX_CLIENTID ` |
|
-Thumbprint $env:CDX_THUMBPRINT ` |
|
-Tenant $env:CDX_TENANTID ` |
|
-ErrorAction Stop |
|
|
|
# Get all site collections |
|
$sites = Get-PnPTenantSite -Filter "LockState -eq 'Unlock'" |
|
|
|
$startDate = [DateTime]::Today.AddDays(-90) |
|
$endDate = [DateTime]::Today |
|
|
|
$results = foreach( $site in $sites ) |
|
{ |
|
Connect-PnPOnline -Url $site.Url ` |
|
-ClientId $env:CDX_CLIENTID ` |
|
-Thumbprint $env:CDX_THUMBPRINT ` |
|
-Tenant $env:CDX_TENANTID ` |
|
-ErrorAction Stop |
|
|
|
|
|
# Check if the MixedReality feature is enabled |
|
$feature = Get-PnPFeature -Identity "f4c52091-703d-431c-ac2d-41f9f257052a" -Scope Site |
|
|
|
if( $feature.DefinitionId -eq $featureGuid ) |
|
{ |
|
$pagesLibrary = Get-PnPList -Identity "SitePages" |
|
|
|
$spacePages = Get-PnPListItem -List $pagesLibrary | Where-Object {$_.FieldValues.MetaInfo -match 'ContentTypeId:SW\|0x0101009D1CB255DA76424F860D91F20E6C41180043153F945E98468297E67C3EEE43AB7000'} |
|
|
|
foreach( $spacePage in $spacePages ) |
|
{ |
|
|
|
$getSharingInformationUrl = "/_api/web/Lists('{0}')/GetItemById({1})/GetSharingInformation" -f $pagesLibrary.Id, $spacePage.Id |
|
|
|
$listItemInformation = Invoke-PnPSPRestMethod -Method POST -Url $getSharingInformationUrl -Content "" -ErrorAction Stop |
|
|
|
$analyticsUrl = '{0}/analytics/allTime?$expand=activities($filter=access ne null)' -f $listItemInformation.itemUrl |
|
|
|
$analytics = Invoke-PnPSPRestMethod -Method Get -Url $analyticsUrl -ErrorAction Stop |
|
|
|
[PSCustomObject]@{ |
|
SiteUrl = $site.Url |
|
PageUrl = $spacePage.FieldValues.FileRef |
|
ViewersCount = $analytics.access.actorCount # The number of times the action took place |
|
ViewsCount = $analytics.access.actionCount # The number of distinct actors that performed the action |
|
} |
|
} |
|
} |
|
} |
|
|
|
$results | Export-Csv -Path "SharePointSpacePageInstances.csv" -NoTypeInformation |