troubleshooting Question

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

Avatar of Achievement_First
Achievement_First asked on
PowershellWindows 7
5 Comments1 Solution4339 ViewsLast Modified:
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  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:
$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
$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 -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???

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros