11function Get-CIPPSPOTenant {
22 [CmdletBinding ()]
3- Param (
3+ param (
44 [Parameter (Mandatory = $true )]
55 [string ]$TenantFilter ,
6- [string ]$SharepointPrefix
6+ [string ]$SharepointPrefix ,
7+ [switch ]$SkipCache
78 )
89
910 if (! $SharepointPrefix ) {
@@ -16,14 +17,34 @@ function Get-CIPPSPOTenant {
1617 $AdminUrl = " https://$ ( $tenantName ) -admin.sharepoint.com"
1718 }
1819
20+ $Table = Get-CIPPTable - tablename ' cachespotenant'
21+ $Filter = " PartitionKey eq 'Tenant' and RowKey eq '$TenantFilter ' and Timestamp gt datetime'$ ( (Get-Date ).AddHours(-1 ).ToString(' yyyy-MM-ddTHH:mm:ssZ' ) ) '"
22+ if (! $SkipCache.IsPresent ) {
23+ $CachedTenant = Get-CIPPAzDataTableEntity @Table - Filter $Filter
24+ if ($CachedTenant -and (Test-Json $CachedTenant.JSON )) {
25+ $Results = $CachedTenant.JSON | ConvertFrom-Json
26+ return $Results
27+ }
28+ }
29+
1930 # Query tenant settings
2031 $XML = @'
2132<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SharePoint Online PowerShell (16.0.24908.0)" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="106" ObjectPathId="105" /><Query Id="107" ObjectPathId="105"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Constructor Id="105" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>
2233'@
2334 $AdditionalHeaders = @ {
2435 ' Accept' = ' application/json;odata=verbose'
2536 }
37+
2638 $Results = New-GraphPostRequest - scope " $ ( $AdminUrl ) /.default" - tenantid $TenantFilter - Uri " $ ( $SharePointInfo.AdminUrl ) /_vti_bin/client.svc/ProcessQuery" - Type POST - Body $XML - ContentType ' text/xml' - AddedHeaders $AdditionalHeaders
2739
28- $Results | Select-Object - Last 1 * , @ {n = ' SharepointPrefix' ; e = { $tenantName } }, @ {n = ' TenantFilter' ; e = { $TenantFilter } }
40+ $Results = $Results | Select-Object - Last 1 * , @ {n = ' SharepointPrefix' ; e = { $tenantName } }, @ {n = ' TenantFilter' ; e = { $TenantFilter } }
41+
42+ # Cache result
43+ $Entity = @ {
44+ PartitionKey = ' Tenant'
45+ RowKey = $TenantFilter
46+ JSON = [string ]($Results | ConvertTo-Json - Depth 10 - Compress)
47+ }
48+ Add-CIPPAzDataTableEntity @Table - Entity $Entity - Force
49+ return $Results
2950}
0 commit comments