src/Solutions/Customization/Commands/Get-XrmCommands.ps1
|
<# .SYNOPSIS Retrieve command records from Microsoft Dataverse. .DESCRIPTION Get appaction records (command bar buttons) optionally filtered by table. Commands have no draft: every command is returned, published or not. .PARAMETER XrmClient Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient) .PARAMETER EntityLogicalName Table / Entity logical name to filter commands by context (contextvalue). Optional. .PARAMETER Columns Specify expected columns to retrieve. (Default : all columns) .OUTPUTS PSCustomObject[]. Array of appaction records (XrmObject). .EXAMPLE $commands = Get-XrmCommands; $accountCommands = Get-XrmCommands -EntityLogicalName "account"; .LINK https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Get-XrmCommands.md #> function Get-XrmCommands { [CmdletBinding()] [OutputType([PSCustomObject[]])] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $false)] [string] $EntityLogicalName, [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [string[]] $Columns = @("*") ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $query = New-XrmQueryExpression -LogicalName "appaction" -Columns $Columns; if ($PSBoundParameters.ContainsKey('EntityLogicalName')) { # contextentity is a lookup to the entity table; contextvalue holds the table logical name (required by the platform with Context 1) $query = $query | Add-XrmQueryCondition -Field "contextvalue" -Condition Equal -Values $EntityLogicalName; } $XrmClient | Get-XrmMultipleRecords -Query $query; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-XrmCommands -Alias *; Register-ArgumentCompleter -CommandName Get-XrmCommands -ParameterName "EntityLogicalName" -ScriptBlock { param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters) $validLogicalNames = Get-XrmEntitiesLogicalName; return $validLogicalNames | Where-Object { $_ -like "$wordToComplete*" }; } |