/build/static/layout/Breadcrumb_cap_w.png

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



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

Answers (2)

Answer Summary:
Posted by: Gerhart 5 years ago
Green Belt
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
Posted by: auntie4life 5 years ago
Senior White Belt
-1

Answered!

 
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