Scripting Question

Need help with a PowerShell script that removes multiple computers from a domain (K1000)

12/09/2019 550 views

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

Answer Summary:
1 Comment   [ + ] Show comment


  • This is the error I get...

    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
    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

Answer Chosen by the Author


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

Answered 12/10/2019 by: Gerhart
Green Belt

  • Well, you are officially my Hero!
    Thank you so much.

All Answers



Answered 12/10/2019 by: auntie4life
Senior White Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ