Link to home
Start Free TrialLog in
Avatar of Achievement_First
Achievement_First

asked on

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

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/questions/25218688/how-to-add-windows-7-computer-to-domain-using-comand-line-Powershell.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???
Avatar of dj_alik
dj_alik

See this:
“Correct” way to programatically join a Windows 7 machine to the domain
http://serverfault.com/questions/154397/correct-way-to-programatically-join-a-windows-7-machine-to-the-domain
Avatar of Achievement_First

ASKER

dj_alik

Thanks for the suggestion, but do you know why the Powershell commands that I type in don't work.
Also, my goal is to have this work automatically when the Administrator logs in over a wireless network.  Is it possible to put a command in, let's say, the runonce registry?
Where can I download netdom.exe for the 64bit version of Windows 7 Enterprise?
ASKER CERTIFIED SOLUTION
Avatar of Achievement_First
Achievement_First

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found the error in the command string I was typing.