Need help with a PowerShell script that removes multiple computers from a domain (K1000)
Hi all. I am in need of some help with a PS1 script. I wnat to remove multiple computers from our domain using one .PS1 script that runs in the K1 against a device label.
Here's what I have, but it’s definitely not right.
Any help would be REALLY appreciated!
$dc = "ourdomain"
$pw = "ourpassword" | ConvertTo-SecureString -asPlainText -Force
$usr = "$dc\Username"
$pc = Get-Content -Path \\blah\blah\computerlist.txt
$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)
Remove-Computer -ComputerName $pc -Credential ourdomain\Username -DomainName $dc -Credential $creds -Restart -Force
Answers (2)
Top Answer
in last line you have the Parameter -credential twice.These Parameters does not work with cmdlet Remove-Computer.
you can try this:
$pw = "ourpassword" | ConvertTo-SecureString -asPlainText -Force
$usr = "$dc\Username"
$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)
Remove-Computer -ComputerName (Get-Content -Path \\blah\blah\computerlist.txt) -LocalCredential $creds -UnjoinDomainCredential $creds -WorkgroupName "Workgroup" -Restart -Force
Comments:
-
Well, you are officially my Hero!
Thank you so much. - auntie4life 5 years ago
Remove-Computer : Cannot bind parameter because parameter 'UnjoinDomainCredential' is specified more than once. To
provide multiple values to parameters that can accept multiple values, use the array syntax. For example, "-parameter
value1,value2,value3".
At line:6 char:89
+ ... rs -Credential domain.org\username -DomainName $dc -Credential $creds ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-Computer], ParameterBindingException
+ FullyQualifiedErrorId : ParameterAlreadyBound,Microsoft.PowerShell.Commands.RemoveComputerCommand - auntie4life 5 years ago