We help IT Professionals succeed at work.
Get Started

"The format of the specified domain name is invalid" error in Powershell Add-Computer

Achievement_First
on
4,323 Views
Last Modified: 2012-05-11
Hello Experts,
Need some help.  I'm building a Windows 7 image and need to run a Powershell script to automatically join the domain.  I first wanted to store the credential password to join the domain (see CTcharger's comments at https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_25218688.html?sfQueryTermInfo=1+10+30+7+domain+join+powershel+window).  But when trying to actually join the computer to the domain I get as error that states "The format of the specified domain name is invalid".  Here are the steps I've taken in powershell:
#Set-myCredential.ps1
$Credential = Get-Credential (I type in the credentials it asks me for)
$credential.Password | ConvertFrom-SecureString | Set-Content c:\windows\system32\windowspowershell\v1.0\password.txt
#Get-myCredential.ps1
$password = Get-Content c:\windows\system32\windowspowershell\v1.0\scriptpass.txt | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential "CachedUser",$password

After that I try to join it to the domain by typing in:
add-computer -domainname af.org -credential $credential -passthru

And that's when I get this error:
Add-Computer : This command cannot be executed on target computer ('ComputerName') due to the following error: The format of the specified domain name in invalid.
At line:1 char:13

If I type in the add-computer command manually putting in the credentials, it will join.  But cannot do it with the stored passwords.  What's up with that???
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE