AdminService add/delete rules in collection

New Contributor

Hi I'm trying to add and delete devices from a collection via AdminService on Configuration manager 2203 from PowerShell.

When I try the below command I receive an error

Invoke-RestMethod -Method Post -Uri "https://<ServerName>/AdminService/wmi/SMS_Collection('<CollectionID>')/AdminService.AddMembershipRule" -Credential $Credentials  -Body "{'collectionRule':{'RuleName':'<DeviceName>'}}"  -ContentType "application/json"


Error:
Invoke-RestMethod : {"error":{"code":"500","message":"An error with description \"Could not get CCollectionRule* from instance\" occurred when
performing MethodExecution operation on WMI class: SMS_Collection."}}
At line:1 char:1

 

Error log AdminService.log
Management exception caught: Could not get CCollectionRule* from instance
System.Management.ManagementException: Not found
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at Microsoft.ConfigurationManager.AdminService.ManagementObjectAbstraction.InvokeMethod(String methodName, IManagementBaseObject inParams, InvokeMethodOptions invokeOptions, WindowsIdentity windowsIdentity)

I get the same error if I try to delete a device from a collection.

Anybody able to help ??

Regards Martin

0 Replies