param( [Parameter(Mandatory = $true)] [Alias('WebUrl')] [string]$SiteUrl, [string]$TermSetName = '', [string]$CssUrl = '', [switch]$EnableDebug, [string]$Description = 'MSFT-Custom-Solution:MegaMenu' ) Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null $componentId = 'abc3361f-bb2d-491f-aba3-cd51c19a299b' $location = 'ClientSideExtension.ApplicationCustomizer' $name = 'MegaMenu' $title = 'Mega Menu' function Get-MegaMenuPropertiesJson { param( [string]$CurrentTermSetName, [string]$CurrentCssUrl, [bool]$CurrentDebug ) return (@{ termSetName = $CurrentTermSetName cssUrl = $CurrentCssUrl debug = $CurrentDebug } | ConvertTo-Json -Depth 10 -Compress) } function Remove-WebScopedComponentActions { param( [Microsoft.SharePoint.SPSite]$CurrentSite, [string]$CurrentComponentId, [string]$CurrentLocation ) $removedCount = 0 foreach ($web in $CurrentSite.AllWebs) { try { $webActions = @($web.UserCustomActions | Where-Object { $_.Location -eq $CurrentLocation -and $_.ClientSideComponentId -and $_.ClientSideComponentId.ToString().ToLower() -eq $CurrentComponentId }) foreach ($webAction in $webActions) { $web.UserCustomActions.Delete($webAction.Id) $removedCount++ } if ($webActions.Count -gt 0) { $web.Update() } } finally { $web.Dispose() } } return $removedCount } $site = Get-SPSite -Identity $SiteUrl try { $removedWebScopedActions = Remove-WebScopedComponentActions -CurrentSite $site -CurrentComponentId $componentId -CurrentLocation $location $existingAction = $site.UserCustomActions | Where-Object { $_.Location -eq $location -and $_.ClientSideComponentId -and $_.ClientSideComponentId.ToString().ToLower() -eq $componentId } | Select-Object -First 1 if ($existingAction) { $action = $existingAction Write-Host 'Aktualisiere vorhandene site-scoped Mega Menu UserCustomAction...' -ForegroundColor Yellow } else { $action = $site.UserCustomActions.Add() Write-Host 'Erstelle neue site-scoped Mega Menu UserCustomAction...' -ForegroundColor Yellow } $action.Name = $name $action.Title = $title $action.Description = $Description $action.Location = $location $action.ClientSideComponentId = [Guid]$componentId $action.ClientSideComponentProperties = Get-MegaMenuPropertiesJson -CurrentTermSetName $TermSetName -CurrentCssUrl $CssUrl -CurrentDebug ([bool]$EnableDebug.IsPresent) $action.Update() Write-Host 'Mega Menu wurde site-scoped registriert.' -ForegroundColor Green Write-Host ('Entfernte web-scoped Eintraege: ' + $removedWebScopedActions) Write-Host ('Beschreibung: ' + $Description) Write-Host ('Properties: ' + $action.ClientSideComponentProperties) } finally { if ($site) { $site.Dispose() } }