Below is a simple little script that removes a computer from SCCM collection. The script works fine removing one computer at a time. I would like to have the option of removing one or multiple computers. I was wondering if there is a way to have the script read a list of computers from a text file and remove the computers from the collection. In addition to reading from a text file, I would like to also be able to remove computers by typing a computer name directly on the screen or multiple computer names on the screen separated comma. Thanks!
Script:
$username =”domain\user”
$password = “mypassword!”
$Computername = Read-Host “Type a Computer Name”
$secstr= new-object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secstr
$compObject = get-wmiobject -query “select * from SMS_R_SYSTEM WHERE Name=’$Computername’” -computername myofficecomputer -Credential $cred -namespace “ROOT\SMS\site_HH1″
$compObject.psbase.delete()