[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$SiteUrl, [Parameter(Mandatory = $true)] [string]$ListTitle, [Parameter(Mandatory = $true)] [string]$ExpiryFieldInternalName, [Guid]$FieldCustomizerComponentId = 'a555f4fc-d6a6-4421-8189-457449d9bbde' ) $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)'." } $alreadyBound = $field.ClientSideComponentId -eq $FieldCustomizerComponentId $field.ClientSideComponentId = $FieldCustomizerComponentId if (-not $alreadyBound -or [string]::IsNullOrWhiteSpace($field.ClientSideComponentProperties)) { $field.ClientSideComponentProperties = (@{ expiryField = $field.InternalName } | ConvertTo-Json -Compress) } $field.Update() # Remove the temporary list-scoped command registration used by older # diagnostic scripts. The app feature owns the production registration. $customActions | Where-Object { $_.Name -eq 'ExpiryIndicator.CommandSet' } | ForEach-Object { $_.DeleteObject() } $context.ExecuteQuery() Write-Host "ExpiryIndicator wurde für '$($list.Title)' an '$($field.InternalName)' gebunden." } finally { $context.Dispose() }