Skip to content

Commit e761443

Browse files
authored
Merge pull request #530 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 95af8bb + 0e460f8 commit e761443

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Modules/CIPPCore/Public/Get-CIPPSPOTenant.ps1

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
function 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
}

Modules/CIPPCore/Public/Set-CIPPSPOTenant.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Set-CIPPSPOTenant {
2929
3030
#>
3131
[CmdletBinding(SupportsShouldProcess = $true)]
32-
Param(
32+
param(
3333
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
3434
[string]$TenantFilter,
3535
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
@@ -65,7 +65,7 @@ function Set-CIPPSPOTenant {
6565
}
6666
$xml = @"
6767
<SetProperty Id="$x" ObjectPathId="110" Name="$Property">
68-
<Parameter Type="Boolean">$($PropertyToSet)</Parameter>
68+
<Parameter Type="$PropertyType">$($PropertyToSet)</Parameter>
6969
</SetProperty>
7070
"@
7171
$SetProperty.Add($xml)

0 commit comments

Comments
 (0)