param( [Parameter(Mandatory = $true)] [Alias('WebUrl')] [string]$SiteUrl, [string]$TermSetName = '', [string]$TermSetId = '', [ValidateRange(1, 1440)] [int]$CacheMinutes = 15, [switch]$EnableDebug, [string]$Description = 'MSFT-Custom-Solution:MegaMenu' ) if (-not (Get-Command -Name Get-SPSite -ErrorAction SilentlyContinue)) { if (Get-Module -ListAvailable -Name Microsoft.SharePoint.PowerShell) { Import-Module Microsoft.SharePoint.PowerShell -DisableNameChecking } elseif (Get-PSSnapin -Registered -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) { Add-PSSnapin Microsoft.SharePoint.PowerShell } else { throw 'Die SharePoint PowerShell-Komponenten wurden nicht gefunden. Bitte in der SharePoint Management Shell ausfuehren.' } } $componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506' $legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b' $location = 'ClientSideExtension.ApplicationCustomizer' $configurationProperty = 'PortalSettings.MegaMenu.Configuration' $properties = [string](@{ termSetName = $TermSetName termSetId = $TermSetId cacheMinutes = $CacheMinutes debug = [bool]$EnableDebug.IsPresent } | ConvertTo-Json -Depth 10 -Compress) $site = Get-SPSite -Identity $SiteUrl try { $rootWeb = $site.RootWeb $rootWeb.AllProperties[$configurationProperty] = [string]$properties $rootWeb.Update() $siteActions = @( $site.UserCustomActions | Where-Object { $_.ClientSideComponentId -eq $componentId -or $_.ClientSideComponentId -eq $legacyComponentId } ) foreach ($siteAction in $siteActions) { $siteAction.Delete() } $created = 0 $updated = 0 $removedLegacy = 0 foreach ($web in $site.AllWebs) { try { $actions = @( $web.UserCustomActions | Where-Object { $_.ClientSideComponentId -eq $componentId -or $_.ClientSideComponentId -eq $legacyComponentId } ) $currentAction = $actions | Where-Object { $_.ClientSideComponentId -eq $componentId } | Select-Object -First 1 foreach ($existingAction in $actions) { if ($currentAction -and $existingAction.Id -eq $currentAction.Id) { continue } $existingAction.Delete() $removedLegacy++ } if (-not $currentAction) { $currentAction = $web.UserCustomActions.Add() $currentAction.Name = [Guid]::NewGuid().ToString('B') $created++ } else { $updated++ } $currentAction.Title = 'MegaMenu Application Customizer' $currentAction.Description = $Description $currentAction.Location = $location $currentAction.ClientSideComponentId = $componentId $currentAction.ClientSideComponentProperties = $properties $currentAction.Sequence = 100 $currentAction.Update() $web.Update() Write-Host ('MegaMenu synchronisiert: ' + $web.Url) -ForegroundColor Green } finally { $web.Dispose() } } Write-Host '' Write-Host 'MegaMenu wurde fuer die gesamte Site Collection konfiguriert.' -ForegroundColor Green Write-Host ('Zentrale Konfiguration: ' + $configurationProperty) Write-Host ('Neu registrierte Webs: ' + $created) Write-Host ('Aktualisierte Webs: ' + $updated) Write-Host ('Entfernte alte oder doppelte Registrierungen: ' + $removedLegacy) Write-Host ('Properties: ' + $properties) Write-Host 'Neue Unterwebs koennen durch erneutes Ausfuehren idempotent synchronisiert werden.' -ForegroundColor Yellow } finally { if ($site) { $site.Dispose() } }