Functions/Organization/Set-CdsOrganizationClientFeature.ps1

<#
    .SYNOPSIS
    Set Organization Client Feature
#>

function Set-CdsOrganizationClientFeature {
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$false, ValueFromPipeline)]
        [Microsoft.Xrm.Tooling.Connector.CrmServiceClient]
        $CdsClient = $Global:CdsClient,

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

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Value
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {
        $features = $CdsClient | Get-CdsOrganizationClientFeatures;

        $featuresXml = "<clientfeatures>";
        foreach($featureKey in $features.Keys)
        {
            if($featureKey -eq $Name)
            {
                continue;
            }
            $featureValue = $features[$featureKey];

            $featuresXml += '<clientfeature xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance">';
            $featuresXml += "<name>$featureKey</name>";
            $featuresXml += "<value>$featureValue</value>";
            $featuresXml += '</clientfeature>';
        }
        $featuresXml += '<clientfeature xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance">';
        $featuresXml += "<name>$Name</name>";
        $featuresXml += "<value>$Value</value>";
        $featuresXml += '</clientfeature>';
        $featuresXml += "</clientfeatures>";

        $currentOrganization = $CdsClient | Get-CdsOrganization -Columns "organizationid";
        $organizationUpdate = $currentOrganization.Record;
        $organizationUpdate | Set-CdsAttributeValue -Name "clientfeatureset" -Value $featuresXml | Out-Null;
        $CdsClient | Update-CdsRecord -Record $organizationUpdate;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

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