Skip to content

Instantly share code, notes, and snippets.

@micmaher
Last active March 30, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmaher/caf681c13d2aadcf5bc9 to your computer and use it in GitHub Desktop.
Save micmaher/caf681c13d2aadcf5bc9 to your computer and use it in GitHub Desktop.
#Requires -Modules ConfigurationManager
# Needs Configuration Manager Cmdlets from . . .
# https://technet.microsoft.com/en-us/library/dn958404%28v=sc.20%29.aspx
$list = Invoke-Sqlcmd -Query "SELECT host FROM BUILD.DBO.SCCMBLOCK;" -ServerInstance "MYSQLSVR"
$collectionname = 'Blocked Clients'
Set-Location IRL:
foreach($c in $list.host) {
try {
Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collectionname -ResourceId $(get-cmdevice -Name $c).ResourceID
"Moved $c to Blocked Clients Collection"
}
catch {
"Invalid client or direct membership rule may already exist: $c"
}
try {
Block-CMDevice -DeviceName $c
"Blocked $c"
}
catch {
"Failed to block: $c"
}
}
$list = Invoke-Sqlcmd -Query "delete FROM BUILD.DBO.SCCMBLOCK;" -ServerInstance "MYSQLSVR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment