none
Setting Configuration Item Supported Platforms with Powershell RRS feed

  • Question

  • I am trying to create a configuration item via powershell and set what versions of Windows it applies to. I can create it, but I am unable to select the version of Windows that is supported.

    Here is my code to create the CI and rule.

    $CIName="Cortana-Disable"
    # Create PS Script to check service state
    $DiscoveryScript = @'
    function Get-RegValType([String] $path, [String] $valName) {
        switch ((Get-ItemProperty $path -Name $valName).$valName.gettype().Name)
            {
                "String"{"REG_SZ"; break;}
                "Int32" {"REG_DWORD"; break;}
                "Int64" {"REG_QWORD"; break;}
                "String[]" {"REG_MULTI_SZ"; break;}
                "Byte[]" {"REG_BINARY"}
                default {throw "Unknown type"}
            }
    }
    function Check-Value([String]$Reg_Path, [String]$Reg_Key, [String]$Reg_Value, [String]$Val_Type){
    
        Try {$Returned_Item_Value = Get-ItemPropertyValue -Path $Reg_Path -Name $Reg_Key -ErrorAction SilentlyContinue}
        Catch {Write-Verbose 'Unable to Retrieve Value'}
        If ( $Returned_Item_Value -eq $Reg_Value) {
            If ( (Get-RegValType -path $Reg_Path -valName $Reg_Key) -eq $Val_Type)
                {Write-Host "COMPLIANT"}
            Else
                {Write-Host "NON-COMPLIANT"}
        }
        Else
            {Write-Host "NON-COMPLIANT"}
    }
    Check-Value -Reg_Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search' -Reg_Key 'AllowCortana' -Reg_Value '0' -Val_Type 'REG_DWORD'
    '@
    
    $RemediationScript = @'
    function Set-Value([String]$Reg_Root, [String]$Reg_Path, [String]$Key_Name, [String]$Item_Name, [String]$Item_Value, [String]$Item_Type) {
        $Item_Type2 = switch ($Item_Type) {
            "REG_SZ"{"String"; break;}
            "REG_DWORD" {"DWord"; break;}
            "REG_QWORD" {"QWord"; break;}
            "REG_MUTLI_SZ" {"MultiString"; break;}
            "REG_BINARY" {"Binary"}
            default {throw "Unknown type"}
        }
        $FullPath = ($Reg_Root + $Reg_Path + "\" + $Key_Name)
        $ParentKey = (Get-Item $Reg_Root).OpenSubKey($Reg_Path,$true)
        $SubKey = $ParentKey.CreateSubKey($Key_Name)
        $SubKey.SetValue($Item_Name, $Item_Value, $Item_Type2)
    }
    Set-Value -Reg_Root "HKLM:\" -Reg_Path "SOFTWARE\Policies\Microsoft\Windows" -Key_Name 'Windows Search' -Item_Name 'AllowCortana' -Item_Value '0' -Item_Type 'REG_DWord'
    '@
    
    # Create new CI
    $ci = New-CMConfigurationItem -Name $CIName -CreationType WindowsOS -Description "Disable Cortana search features"
    
    #Create Script Setting
    $ComplianceSettingsScriptArgs=@{
        RuleName="DisableCortana";
        Description="Disable Cortana";
        DataType="String";
        DiscoveryScriptText=$DiscoveryScript;
        DiscoveryScriptLanguage="PowerShell";
        SettingName="Cortana - Disable"; 
        RemediationScriptLanguage="PowerShell"; 
        RemediationScriptText=$RemediationScript;
        ValueRule=$True;
        ExpectedValue="COMPLIANT"; 
        ExpressionOperator="IsEquals";
        NoncomplianceSeverity="Warning";
        ReportNoncompliance=$true
    }
    $CIScript = $ci | Add-CMComplianceSettingScript @ComplianceSettingsScriptArgs -PassThru
    
    Set-CMComplianceRuleValue -InputObject $ci -RuleName "DisableCortana" -Remediate $True

    The Set-CMComplianceSupportedPlatform cmdlet seems like the logical option, but it has zero info in the help or online.

    https://docs.microsoft.com/en-us/powershell/module/configurationmanager/set-cmcompliancesupportedplatform?view=sccm-ps

    When I pipe my CI rule to it it does state that it is "beta-quality" and isn't complete.

    $CIRule | Set-CMComplianceSupportedPlatform 
    WARNING: The 'Set-CMComplianceSupportedPlatform' cmdlet is a beta-quality and is not yet complete. It may not be fully functi
    onal, and may be changed or removed in a future release. It is provided for testing purposes and should not be used for produ
    ction purposes.

    This is on version CM 1806 site version 5.0.8692.1000 with console version 5.1806.1074.1500. Is this feature just not there yet?



    • Edited by MarcGoff Monday, September 24, 2018 3:26 PM misspelling
    Monday, September 24, 2018 3:23 PM

Answers

All replies