param( [Parameter(Mandatory = $true)] [string]$SiteUrl, [string]$TermSetName = '', [string]$TermSetId = '', [ValidateRange(1, 1440)] [int]$CacheMinutes = 15, [string]$CacheVersion = '1', [ValidateSet('megaMenu', 'flyout')] [string]$MenuMode = 'megaMenu', [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' $legacyPropertyName = 'PortalSettings.MegaMenu.Configuration' if ([string]::IsNullOrWhiteSpace($TermSetId) -and [string]::IsNullOrWhiteSpace($TermSetName)) { throw 'Bitte TermSetId oder TermSetName angeben.' } $properties = [string](@{ termSetName = $TermSetName.Trim() termSetId = $TermSetId.Trim() cacheMinutes = $CacheMinutes cacheVersion = $CacheVersion menuMode = $MenuMode debug = [bool]$EnableDebug.IsPresent } | ConvertTo-Json -Depth 10 -Compress) $site = Get-SPSite -Identity $SiteUrl try { @($site.UserCustomActions | Where-Object { $_.ClientSideComponentId -eq $componentId -or $_.ClientSideComponentId -eq $legacyComponentId }) | ForEach-Object { Write-Host ('Entferne alte Site-Action: ' + $_.Id) $_.Delete() } try { if ($site.RootWeb.AllProperties.ContainsKey($legacyPropertyName)) { $site.RootWeb.AllProperties.Remove($legacyPropertyName) $site.RootWeb.Update() Write-Host ('Alte Property-Bag-Konfiguration entfernt: ' + $legacyPropertyName) } } catch { Write-Warning ('Die alte Property-Bag-Konfiguration konnte nicht entfernt werden: ' + $_.Exception.Message) } foreach ($web in $site.AllWebs) { try { $webUrl = $web.Url $actions = @($web.UserCustomActions | Where-Object { $_.ClientSideComponentId -eq $componentId -or $_.ClientSideComponentId -eq $legacyComponentId }) foreach ($action in $actions) { Write-Host ('Entferne alte Web-Action: ' + $webUrl + ' / ' + $action.Id) $action.Delete() } } finally { $web.Dispose() } } } finally { $site.Dispose() } $site = Get-SPSite -Identity $SiteUrl try { $action = $site.UserCustomActions.Add() $action.Name = [Guid]::NewGuid().ToString('B') $action.Title = 'MegaMenu Application Customizer' $action.Description = $Description $action.Location = 'ClientSideExtension.ApplicationCustomizer' $action.ClientSideComponentId = $componentId $action.ClientSideComponentProperties = $properties $action.Sequence = 100 $action.Update() Write-Host '' Write-Host 'MegaMenu wurde zentral fuer die Site Collection registriert.' -ForegroundColor Green Write-Host ('Site Collection: ' + $site.Url) Write-Host ('Action-ID: ' + $action.Id) Write-Host ('Menu mode: ' + $MenuMode) Write-Host ('Properties: ' + $properties) Write-Host 'Das MegaMenu-SPFx-Paket muss im App Catalog zentral bereitgestellt sein.' -ForegroundColor Yellow } finally { $site.Dispose() }