src/Metadata/Remove-XrmAlternateKey.ps1
|
<# .SYNOPSIS Delete an alternate key from a Microsoft Dataverse table. .DESCRIPTION Delete an entity key using DeleteEntityKeyRequest. .PARAMETER XrmClient Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient) .PARAMETER EntityLogicalName Table / Entity logical name. .PARAMETER LogicalName Alternate key logical name to delete. .OUTPUTS Microsoft.Xrm.Sdk.OrganizationResponse. The DeleteEntityKey response. .EXAMPLE Remove-XrmAlternateKey -EntityLogicalName "account" -LogicalName "new_accountcode"; #> function Remove-XrmAlternateKey { [CmdletBinding()] [OutputType([Microsoft.Xrm.Sdk.OrganizationResponse])] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $EntityLogicalName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $LogicalName ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $request = [Microsoft.Xrm.Sdk.Messages.DeleteEntityKeyRequest]::new(); $request.EntityLogicalName = $EntityLogicalName; $request.Name = $LogicalName; $response = Invoke-XrmRequest -XrmClient $XrmClient -Request $request; $response; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Remove-XrmAlternateKey -Alias *; |