src/Themes/Get-XrmTheme.ps1
|
<# .SYNOPSIS Retrieve theme record. .DESCRIPTION Get theme by its name with expected columns. .PARAMETER XrmClient Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient) .PARAMETER Name Theme name to retrieve. .PARAMETER Columns Specify expected columns to retrieve. (Default : All columns) .OUTPUTS PSCustomObject. The theme row (see Get-XrmRecord). Throws an error when no theme has this name. .EXAMPLE $theme = Get-XrmTheme -XrmClient $xrmClient -Name "Contoso" -Columns "name", "navbarbackgroundcolor", "globallinkcolor"; .LINK https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Get-XrmTheme.md #> function Get-XrmTheme { [CmdletBinding()] [OutputType([PSCustomObject])] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $Name, [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 { $theme = Get-XrmRecord -XrmClient $XrmClient -LogicalName "theme" -AttributeName "name" -Value $Name -Columns $Columns; if (-not $theme) { throw "Theme '$Name' not found!"; } $theme; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-XrmTheme -Alias *; Register-ArgumentCompleter -CommandName Get-XrmTheme -ParameterName "Name" -ScriptBlock { param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters) $themeNames = @(); $themes = Get-XrmThemes -Columns "name"; $themes | ForEach-Object { $themeNames += $_.name }; return $themeNames | Where-Object { $_ -like "$wordToComplete*" } | Sort-Object; } |