Last active
March 30, 2016 21:07
-
-
Save micmaher/caf681c13d2aadcf5bc9 to your computer and use it in GitHub Desktop.
This file contains 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
#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