[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$SiteUrl, [Parameter(Mandatory = $true)] [string]$ListTitle, [Parameter(Mandatory = $true)] [string]$ExpiryFieldInternalName, [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde', [Guid]$CommandSetComponentId = 'cd58f5d9-ffc8-4df7-a910-3054842d7abf' ) $isapiPath = Join-Path ([Environment]::GetFolderPath('CommonProgramFiles')) 'microsoft shared\Web Server Extensions\16\ISAPI' Add-Type -Path (Join-Path $isapiPath 'Microsoft.SharePoint.Client.Runtime.dll') Add-Type -Path (Join-Path $isapiPath 'Microsoft.SharePoint.Client.dll') $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials try { $list = $context.Web.Lists.GetByTitle($ListTitle) $field = $list.Fields.GetByInternalNameOrTitle($ExpiryFieldInternalName) $customActions = $list.UserCustomActions $context.Load($list) $context.Load($field) $context.Load($customActions) $context.ExecuteQuery() if ($field.InternalName -ne $ExpiryFieldInternalName) { Write-Warning "Das Feld wurde über seinen Anzeigenamen gefunden. Verwende künftig den internen Namen '$($field.InternalName)'." } $field.ClientSideComponentId = $FieldCustomizerComponentId $field.ClientSideComponentProperties = '{}' $field.Update() $commandAction = $customActions | Where-Object { $_.Name -eq 'ExpiryIndicator.CommandSet' -or $_.ClientSideComponentId -eq $CommandSetComponentId } | Select-Object -First 1 if ($null -eq $commandAction) { $commandAction = $customActions.Add() } $commandAction.Name = 'ExpiryIndicator.CommandSet' $commandAction.Title = 'ExpiryIndicator commands' # SPUserCustomAction uses the classic location value; SharePoint maps it to # the SPFx command bar and item context menu when ClientSideComponentId is set. $commandAction.Location = 'CommandUI.Ribbon' $commandAction.ClientSideComponentId = $CommandSetComponentId $commandAction.ClientSideComponentProperties = '{}' $commandAction.Update() $context.ExecuteQuery() Write-Host "Field Customizer wurde an '$($field.InternalName)' gebunden." Write-Host "Command Set wurde an '$($list.Title)' registriert." Write-Host 'Bitte die moderne Listenansicht mit Strg+F5 neu laden.' } finally { $context.Dispose() }