Remove member from SCCM collection
param(
[Parameter(Mandatory=$true)]
[String]$serverslistfile,
[Parameter(Mandatory=$true)]
[String]$collectionName,
[String]$smsServer = 'SCCMDPservername',
[String]$smsNamespace = 'root\sms\site_NAME'
)
$serverslist = Get-Content $serverslistfile
function remove-fromCollection {
$collection = Get-WmiObject -ComputerName $smsServer -Query "select * from SMS_Collection where Name LIKE '$collectionName'" -Namespace $smsNamespace #-Credential $Cred
$collection.get()
$serverslist.Split(",") | foreach {
$serverName = $_.split(".")[0]
Write-Host $serverName
$rule = $collection.CollectionRules | where {$_.RuleName -eq "$serverName"}
$collection.DeleteMemberShipRule($rule)
}
}
remove-fromCollection
Delete computer from SCCM
param(
[String]$serverslistfile,
[String]$smsServer = ‘SCCMDPservername’,
[String]$smsNamespace = 'root\sms\site_NAME'
)
$serverslist = Get-Content $serverslistfile
function delete-device {
$serverslist | foreach {
$serverName = $_.split(".")[0]
$resource = Get-WmiObject -ComputerName $smsServer -Query "select * from SMS_R_SYSTEM where Name LIKE '$serverName'" -Namespace $smsNamespace
write-host "Deleting $serverName"
$resource.delete()
}
}
delete-device
No comments:
Post a Comment