Hi Powershell guys,
I have a script that I created to pass credentials onto add-computer which would automate joining that machine to the domain. It’s been working since I created it but recently I had to change the password for some testing. The password length and complexity was the same (although I don’t think it really would matter), but the script broke.
Now whenever I run it, it tells me that my password is incorrect. If I take the passed credentials out and I just have it prompt me, the script works. That defeats the purpose though because it’s supposed to be automated. Does anyone know why this could have happened? I’ve attached the script which contains the code and also the error message… Any help would be greatly appreciated!
<# This function joins the VM to the domain #> function JoinDom { Add-computer -domainname mydomain.domain -credential $Adcred -computername ipaddress -localcredential $cred -restart "Rebooting VM after joining Domain..." } $creduser = "administrator" $credpass = convertto-securestring -String "password" -AsPlainText -Force $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $creduser,$credpass $Aduser = "domain\lkong" $Adpass = convertto-securestring -string "mixedcharacterspassword" -AsPlainText -Force $Adcred = new-object -typename System.Management.Automation.PSCredential -argumentlist $Aduser,$Adpass
ERROR MESSAGE:
Add-computer : Computer 'xxx.xxx.xxx.xxx' failed to join domain 'mydomain.domain' from its current workgroup 'WORKGROUP' with following error message: The user name or password is incorrect. At C:\vmscripts\ADrename.ps1:13 char:2 + Add-computer -domainname mydomain.domain -credential $Adcred -computername $ip -lo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (128.149.3.171:String) [Add-Computer], InvalidOperationException + FullyQualifiedErrorId : FailToJoinDomainFromWorkgroup,Microsoft.PowerShell.Commands.AddComputerCommand
Thanks in advance!
Leonard