Created
June 27, 2021 02:25
-
-
Save rezarahimian/cf7e6635c932521129cbf455facab65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module -Name 'ConfigurationManager' | |
$SiteCode = 'LCL' | |
$Location = Get-Location | |
Set-Location $SiteCode":\" -ErrorAction 'Stop' | |
$Collection = Get-CMDeviceCollection -Name 'HR_Servers' | |
if ($Collection) | |
{ | |
$Rule = $Collection | Get-CMDeviceCollectionQueryMembershipRule | Where-Object { $_.RuleName -eq 'HR server manaul query' } | |
if ($Rule){ Remove-CMDeviceCollectionQueryMembershipRule -CollectionId $Collection.CollectionID -RuleName $Rule.RuleName -Force } | |
$Query = 'select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUnqiueIdentifier,SMS_R_SYSTEM.ResourceDomainOrWorkgroup,SMS_R_SYSTEM.Client from SMS_R_SYSTEM WHERE SMS_R_SYSTEM.NetbiosName IN (SRVHR1,SRVHR2,SRVHR3,SRVSQL1)' | |
Add-CMDeviceCollectionQueryMembershipRule -CollectionId $Collection.CollectionID -RuleName $Rule.RuleName -QueryExpression $Query | |
} | |
$Location | Set-Location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment