From e0e2a04b6a9165ea73138b74c67c3630624eba86 Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Sat, 8 Jun 2024 09:13:46 -0500 Subject: [PATCH] fix: add check for length in 7.3.4 details. --- source/tests/Test-RestrictCustomScripts.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/tests/Test-RestrictCustomScripts.ps1 b/source/tests/Test-RestrictCustomScripts.ps1 index 34017ca..99daa5a 100644 --- a/source/tests/Test-RestrictCustomScripts.ps1 +++ b/source/tests/Test-RestrictCustomScripts.ps1 @@ -20,9 +20,9 @@ function Test-RestrictCustomScripts { # Retrieve all site collections and select necessary properties $SPOSitesCustomScript = Get-SPOSite -Limit All | Select-Object Title, Url, DenyAddAndCustomizePages - # Replace 'sharepoint.com' with '' + # Replace 'sharepoint.com' with '' $processedUrls = $SPOSitesCustomScript | ForEach-Object { - $_.Url = $_.Url -replace 'sharepoint\.com', '' + $_.Url = $_.Url -replace 'sharepoint\.com', '' $_ } @@ -55,8 +55,8 @@ function Test-RestrictCustomScripts { # Gather details for non-compliant sites (where custom scripts are allowed) $nonCompliantSiteDetails = $customScriptAllowedSites | ForEach-Object { $url = $_.Url - if ($null -ne $mostUsedHostname -and $url -match "^https://$mostUsedHostname\.") { - $url = $url -replace "^https://$mostUsedHostname\.", "https://." + if ($null -ne $mostUsedHostname -and $url -match "^https://$mostUsedHostname\.") { + $url = $url -replace "^https://$mostUsedHostname\.", "https://." } "$(if ($_.Title) {$_.Title} else {"NoTitle"})|$url" } @@ -76,6 +76,16 @@ function Test-RestrictCustomScripts { "Title|Url`n" + ($nonCompliantSiteDetails -join "`n") } + # Convert details to PSObject and check length + $detailsPSObject = $details | ConvertFrom-Csv -Delimiter '|' + $detailsLength = ($detailsPSObject | ForEach-Object { $_.Url }).Length + + if ($detailsLength -gt 32767) { + # Create a preview of the first 10 results + $preview = $detailsPSObject | Select-Object -First 10 | ForEach-Object { "$($_.Title)|$($_.Url)" } + $details = "The output is too large. Here is a preview of the first 10 results:`n`n" + ($preview -join "`n") + "`n`nPlease run the test with the following commands to get the full details:`n`nGet-SPOSite -Limit All | Where-Object { `$.DenyAddAndCustomizePages -ne 'Enabled' } | Select-Object Title, Url" + } + # Create and populate the CISAuditResult object $params = @{ Rec = $recnum