Files
CurrentNavigation/deployment/add-currentnavigation.ps1

61 lines
2.8 KiB
PowerShell

param(
[Parameter(Mandatory = $true)][string]$SiteUrl,
[Parameter(Mandatory = $true)][string]$TermSetId,
[int]$CacheMinutes = 15,
[string]$CacheVersion = '1',
[ValidateRange(1, 8)][int]$MaxDepth = 3,
[switch]$ShowRoot,
[ValidateSet('activePath', 'expanded', 'collapsed')][string]$InitialExpansion = 'activePath',
[switch]$EnableDebug
)
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 'Bitte in der SharePoint Management Shell ausführen.' }
}
$componentId = [Guid]'e37b828f-4315-461a-b1b0-fcf991deda3d'
$parsedTermSetId = [Guid]::Empty
if (-not [Guid]::TryParse($TermSetId, [ref]$parsedTermSetId)) { throw 'TermSetId ist keine gültige GUID.' }
$properties = @{
schemaVersion = 1
portalSettings = @{ providerKey = 'currentnavigation'; contractVersion = 1; minimumPortalSettingsVersion = '3.1.0' }
termSetId = $parsedTermSetId.ToString()
termSetName = ''
cacheMinutes = [Math]::Min([Math]::Max($CacheMinutes, 1), 1440)
cacheVersion = $(if ([string]::IsNullOrWhiteSpace($CacheVersion)) { '1' } else { $CacheVersion.Trim() })
maxDepth = $MaxDepth
showRoot = [bool]$ShowRoot.IsPresent
initialExpansion = $InitialExpansion
debug = [bool]$EnableDebug.IsPresent
}
$site = Get-SPSite -Identity $SiteUrl
try {
$actions = @($site.UserCustomActions | Where-Object {
$_.Location -eq 'ClientSideExtension.ApplicationCustomizer' -and $_.ClientSideComponentId -eq $componentId
})
$action = $actions | Select-Object -First 1
if (-not $action) { $action = $site.UserCustomActions.Add() }
$action.Name = 'CurrentNavigation'
$action.Title = 'Current Navigation Application Customizer'
$action.Description = 'MSFT-Custom-Solution:CurrentNavigation'
$action.Location = 'ClientSideExtension.ApplicationCustomizer'
$action.Sequence = 110
$action.ClientSideComponentId = $componentId
$action.ClientSideComponentProperties = $properties | ConvertTo-Json -Depth 10 -Compress
$action.Update()
@($actions | Select-Object -Skip 1) | ForEach-Object { $_.Delete() }
foreach ($web in $site.AllWebs) {
try {
@($web.UserCustomActions | Where-Object {
$_.Location -eq 'ClientSideExtension.ApplicationCustomizer' -and $_.ClientSideComponentId -eq $componentId
}) | ForEach-Object { $_.Delete() }
} finally { $web.Dispose() }
}
Write-Host 'CurrentNavigation wurde für die Site Collection registriert.' -ForegroundColor Green
} finally { if ($site) { $site.Dispose() } }