src/Themes/Set-XrmThemeColor.ps1

<#
    .SYNOPSIS
    Change theme color.
    
    .DESCRIPTION
    Set theme accent color.
    Update the link and header color (globallinkcolor, headercolor) and the navigation bar background color (navbarbackgroundcolor) of the theme. Publish the theme to apply the change (see Publish-XrmTheme).

    .PARAMETER XrmClient
    Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient)

    .PARAMETER Name
    Theme name to update.

    .PARAMETER LabelAndLinkColor
    Color of the links and headers (globallinkcolor, headercolor), as a hexadecimal code (e.g. #0078D4).

    .PARAMETER BackgroundColor
    Background color of the navigation bar (navbarbackgroundcolor), as a hexadecimal code (e.g. #002050).

    .OUTPUTS
    Microsoft.Xrm.Sdk.EntityReference. Reference of the updated theme.

    .EXAMPLE
    Set-XrmThemeColor -XrmClient $xrmClient -Name "Contoso" -LabelAndLinkColor "#0078D4" -BackgroundColor "#002050";
    Publish-XrmTheme -XrmClient $xrmClient -Name "Contoso";

    .LINK
    https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Set-XrmThemeColor.md
#>

function Set-XrmThemeColor {
    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([Microsoft.Xrm.Sdk.EntityReference])]
    param
    (        
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient]
        $XrmClient = $Global:XrmClient,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Name,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $LabelAndLinkColor,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $BackgroundColor
    )
    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;
        if (-not $theme) {
            throw "Theme '$Name' not found.";
        }
        $themeUpdate = New-XrmEntity -LogicalName "theme" -Id $theme.Id -Attributes @{
            "globallinkcolor"       = $LabelAndLinkColor
            "headercolor"           = $LabelAndLinkColor
            "navbarbackgroundcolor" = $BackgroundColor
        };
        Update-XrmRecord -XrmClient $XrmClient -Record $themeUpdate;
        $theme.Reference;
    }
    end {
        $StopWatch.Stop();
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Set-XrmThemeColor -Alias *;