Functions/Organization/Set-CdsOrganizationFeature.ps1
<#
.SYNOPSIS Set Organization Feature #> function Set-CdsOrganizationFeature { [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-CdsOrganizationFeatures; $featuresXml = "<features>"; foreach($featureKey in $features.Keys) { if($featureKey -eq $Name) { if($features[$featureKey] -eq $Value) { return; } continue; } $featureValue = $features[$featureKey]; $featuresXml += '<feature xmlns:i="http://www.w3.org/2001/XMLSchema-instance">'; $featuresXml += "<name>$featureKey</name>"; $featuresXml += "<value>$featureValue</value>"; $featuresXml += '</feature>'; } $featuresXml += '<feature xmlns:i="http://www.w3.org/2001/XMLSchema-instance">'; $featuresXml += "<name>$Name</name>"; $featuresXml += "<value>$Value</value>"; $featuresXml += "</feature>"; $featuresXml += "</features>"; $currentOrganization = $CdsClient | Get-CdsOrganization -Columns "organizationid"; $organizationUpdate = $currentOrganization.Record; $organizationUpdate | Set-CdsAttributeValue -Name "featureset" -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-CdsOrganizationFeature -Alias *; |