none
Remove-CMCollectionMembershipRule RRS feed

  • Question

  • I call the function Remove-CMDeviceCollectionDirectMembershipRule. This function is in the Configuration Manager PowerShell files and calls Remove-CMCollectionMembershipRule itself. And when calling this I get this error message: (this is new, the code did already run)

    ---------

    Remove-CMCollectionMembershipRule : The term 'Remove-CMCollectionMembershipRule' is not recognized as the
    name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
    was included, verify that the path is correct and try again.
    At C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\AdminUI.PS.Collections.psm1:1250
    char:9
    +         Remove-CMCollectionMembershipRule -SearchCriteria $searchCrit ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Remove-CMCollectionMembershipRule:String) [], CommandNotFoundE
       xception
        + FullyQualifiedErrorId : CommandNotFoundException

     
    Tuesday, August 27, 2019 11:50 AM

Answers

All replies

  • Make sure that the PowerShell module is available (ConfigurationManager.psd1) and that you connect to the site

    Check this - https://techcommunity.microsoft.com/t5/Configuration-Manager-Archive/PowerShell-8211-Connecting-to-Configuration-Manager/ba-p/273212

    Tuesday, August 27, 2019 1:38 PM
  • Hi Patrick,

    Try the running the below function in the PowerShell ISE on a device that has the Configuration Manager console installed.

    function Get-SMSDRIVE {
        <#
          .SYNOPSIS
          Connects to Configuration Manager drive
          .DESCRIPTION
          This function loads the Configuration Manager PowerShell module and then maps to the Configuration Manager drive, the device must have the Configuration Manager Console installed.
          .EXAMPLE
          Get-SMSDRIVE PS1
          specifies the site code for the site.
          .EXAMPLE
          Get-SMSDRIVE -Sitecode 'PS1'
      #>
        [CmdletBinding()]
        param
        (
            [Parameter(Mandatory = $true, Position = 0)]
            [System.String]
            [ValidateNotNullOrEmpty()]
            [ValidateLength(3, 3)]
            $Sitecode
        
        )
      
        $CMModulePath = $Env:SMS_ADMIN_UI_PATH.ToString().SubString(0, $Env:SMS_ADMIN_UI_PATH.Length - 5) `
            + '\ConfigurationManager.psd1'
        Import-Module $CMModulePath -Force
        Set-Location -Path "$Sitecode`:"
    }

    Then run

    Get-SMSDRIVE -Sitecode PS1

    and swop out PS1 for your site code.

    You should then be able to access the module.



    Richard Knight | Collection Refresh Manager | Automate detection rules for patch \ msp files | Twitter


    Tuesday, August 27, 2019 2:01 PM
  • Thank you for your answers.

    Did try, did not help - I already start this from the SCCM Site Drive.

    I do not think it is about importing / using the module for 2 reasons

    1.) Get-CMSite works

    2.) Remove-CMDeviceCollectionDirectMembershipRule is available and from SCCM. This one calls the function 'Remove-CMCollectionMembershipRule', which is not available


    Tuesday, August 27, 2019 2:23 PM
  • What version of Configuration Manager are you running

    Does the command tab complete like in my picture?


    Richard Knight | Collection Refresh Manager | Automate detection rules for patch \ msp files | Twitter

    Tuesday, August 27, 2019 2:32 PM
  • I have the same command tab.

    I have two servers. One is the CM Server, the other one where I run my scripts. So there may be two diffrent versions.

    That said, Get-CMSite delivers 5.00.8790.1000 - don't know, which server this is.

    Tuesday, August 27, 2019 2:40 PM