Upravit

Sdílet prostřednictvím


Add-CMDeviceCollectionQueryMembershipRule

Add a query membership rule to a device collection.

Syntax

Add-CMDeviceCollectionQueryMembershipRule
   -CollectionId <String>
   [-PassThru]
   -QueryExpression <String>
   -RuleName <String>
   [-ValidateQueryHasResult]
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Add-CMDeviceCollectionQueryMembershipRule
   -CollectionName <String>
   [-PassThru]
   -QueryExpression <String>
   -RuleName <String>
   [-ValidateQueryHasResult]
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Add-CMDeviceCollectionQueryMembershipRule
   -InputObject <IResultObject>
   [-PassThru]
   -QueryExpression <String>
   -RuleName <String>
   [-ValidateQueryHasResult]
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

Use this cmdlet to add a query membership rule to a device collection. A query rule lets you dynamically update the membership of a collection based on a query that is run on a schedule. You can't add membership rules to default collections. Any collection that you target should have an ID that starts with the site code, not SMS. For more information, see How to create collections in Configuration Manager.

Note

Run Configuration Manager cmdlets from the Configuration Manager site drive, for example PS XYZ:\>. For more information, see getting started.

Examples

Example 1: Add a query membership rule

This example first stores the WMI Query Language (WQL) statement into the wql variable. The next command adds a membership rule named TPM to the device collection named Windows 10 devices. The QueryExpression parameter uses the wql variable, and specifies the query that defines the membership rule.

$wql = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System inner join SMS_G_System_TPM on SMS_G_System_TPM.ResourceID = SMS_R_System.ResourceId"

Add-CMDeviceCollectionQueryMembershipRule -CollectionName "Windows 10 devices" -QueryExpression $wql -RuleName "TPM"

Parameters

-CollectionId

Specify the ID of the device collection to add the rule. This value is the CollectionID property, for example, XYZ00012. Since you can't add membership rules to default collections, this ID starts with the site code and not SMS.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-CollectionName

Specify the name of the device collection to add the rule.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DisableWildcardHandling

This parameter treats wildcard characters as literal character values. You can't combine it with ForceWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ForceWildcardHandling

This parameter processes wildcard characters and may lead to unexpected behavior (not recommended). You can't combine it with DisableWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

Specify an object for the device collection to add the rule. To get this object, use the Get-CMCollection or Get-CMDeviceCollection cmdlets.

Type:IResultObject
Aliases:Collection
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-PassThru

Add this parameter to return an object that represents the item with which you're working. By default, this cmdlet may not generate any output.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-QueryExpression

Specify the WMI Query Language (WQL) expression that the site uses to update the device collection.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-RuleName

Specify the name of the query rule to add to the collection.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ValidateQueryHasResult

Add this parameter to test the query expression before adding the rule. When the cmdlet runs with this parameter, if the query expression has no results, the cmdlet returns the following error message: No object corresponds to the specified parameters. In this case, the query isn't added to the collection.

If you know the query currently returns zero results, but still want to add the rule, don't use this parameter.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet doesn't run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.ConfigurationManagement.ManagementProvider.IResultObject

Outputs

System.Object