Skip to content

Instantly share code, notes, and snippets.

@rezarahimian
Created June 27, 2021 02:25
Show Gist options
  • Save rezarahimian/cf7e6635c932521129cbf455facab65b to your computer and use it in GitHub Desktop.
Save rezarahimian/cf7e6635c932521129cbf455facab65b to your computer and use it in GitHub Desktop.
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