From e119573b5ebed2c79c23d254ebfa627c93711fd7 Mon Sep 17 00:00:00 2001 From: Torsten Brendgen Date: Sun, 19 Jul 2026 23:31:42 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20neues=20Skript=20f=C3=BCr=20MegaMen?= =?UTF-8?q?u=20Site-Scope-Test=20hinzu,=20um=20die=20Konfiguration=20zu=20?= =?UTF-8?q?=C3=BCberpr=C3=BCfen=20und=20Site-Actions=20zu=20verwalten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployment/test-megamenu-site-scope.ps1 | 126 ++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 deployment/test-megamenu-site-scope.ps1 diff --git a/deployment/test-megamenu-site-scope.ps1 b/deployment/test-megamenu-site-scope.ps1 new file mode 100644 index 0000000..b2259a7 --- /dev/null +++ b/deployment/test-megamenu-site-scope.ps1 @@ -0,0 +1,126 @@ +param( + [Parameter(Mandatory = $true)] + [string]$SiteUrl, + + [string]$Description = 'MSFT-Custom-Solution:MegaMenu' +) + +Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null + +$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506' +$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b' +$location = 'ClientSideExtension.ApplicationCustomizer' +$configurationProperty = 'PortalSettings.MegaMenu.Configuration' + +$site = Get-SPSite -Identity $SiteUrl + +try { + $rootWeb = $site.RootWeb + $properties = [string]$rootWeb.AllProperties[$configurationProperty] + + if ([string]::IsNullOrWhiteSpace($properties)) { + $existingAction = $null + + foreach ($web in $site.AllWebs) { + try { + $existingAction = @( + $web.UserCustomActions | + Where-Object { + $_.ClientSideComponentId -eq $componentId -or + $_.ClientSideComponentId -eq $legacyComponentId + } + ) | Select-Object -First 1 + + if ($existingAction) { + $properties = [string]$existingAction.ClientSideComponentProperties + break + } + } + finally { + $web.Dispose() + } + } + } + + if ([string]::IsNullOrWhiteSpace($properties)) { + throw ('Keine MegaMenu-Konfiguration im Property Bag oder in einer bestehenden ' + + 'Web-Registrierung gefunden. Bitte zuerst add-megamenu.ps1 ausfuehren.') + } + + try { + $null = $properties | ConvertFrom-Json + } + catch { + throw ('Die gefundene MegaMenu-Konfiguration ist kein gueltiges JSON: ' + $_.Exception.Message) + } + + $removedSiteActions = 0 + @( + $site.UserCustomActions | + Where-Object { + $_.ClientSideComponentId -eq $componentId -or + $_.ClientSideComponentId -eq $legacyComponentId + } + ) | ForEach-Object { + $_.Delete() + $removedSiteActions++ + } + + $siteAction = $site.UserCustomActions.Add() + $siteAction.Name = [Guid]::NewGuid().ToString('B') + $siteAction.Title = 'MegaMenu Application Customizer' + $siteAction.Description = $Description + $siteAction.Location = $location + $siteAction.ClientSideComponentId = $componentId + $siteAction.ClientSideComponentProperties = $properties + $siteAction.Sequence = 100 + $siteAction.Update() + + $removedWebActions = 0 + $testedWebUrls = @() + + foreach ($web in $site.AllWebs) { + try { + $testedWebUrls += $web.Url + + @( + $web.UserCustomActions | + Where-Object { + $_.ClientSideComponentId -eq $componentId -or + $_.ClientSideComponentId -eq $legacyComponentId + } + ) | ForEach-Object { + $_.Delete() + $removedWebActions++ + } + } + finally { + $web.Dispose() + } + } + + $verification = @( + $site.UserCustomActions | + Where-Object { $_.ClientSideComponentId -eq $componentId } + ) + + Write-Host '' + Write-Host '=== MegaMenu Site-Scope-Test vorbereitet ===' -ForegroundColor Green + Write-Host ('Site-Action-ID: ' + $siteAction.Id) + Write-Host ('Component-ID: ' + $componentId) + Write-Host ('Entfernte vorherige Site-Actions: ' + $removedSiteActions) + Write-Host ('Entfernte Web-Actions: ' + $removedWebActions) + Write-Host ('Verifizierte Site-Actions: ' + $verification.Count) + Write-Host ('Properties: ' + $properties) + Write-Host '' + Write-Host 'Bitte jeweils mit Strg+F5 testen:' -ForegroundColor Cyan + $testedWebUrls | ForEach-Object { Write-Host (' ' + $_) } + Write-Host '' + Write-Host 'Rueckkehr zum bisherigen Web-Scope:' -ForegroundColor Yellow + Write-Host ('.\deployment\add-megamenu.ps1 -SiteUrl ''' + $site.Url + '''') +} +finally { + if ($site) { + $site.Dispose() + } +}