troubleshooting Question

Running Powershell Script To Join Domain after running Sysprep in Windows 7

Avatar of Achievement_First
Achievement_First asked on
PowershellWindows 7Networking
8 Comments2 Solutions13782 ViewsLast Modified:
I'm working on a Windows 7 image that will join the computer to the domain automatically.  I'm trying to accomplish this through a Powershell script.  While logged in as Administrator, I set the execution policy to remotesigned.  Then I use Get-Credential to Store Passwords “securely” in a file (see  I create a script with the following commands:

$password = Get-Content c:\windows\system32\windowspowershell\v1.0\password.txt | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential "Domain\domainuser",$password
add-computer -domainname Domain -credential $credential -passthru

I save the script in c:\windows\system32\windowspowershell\v1.0\ and I place the run script command in the Administrator's runonce registry entry.

The problem:
1. It appears that Powershell reverts back to "Restricted" mode after running sysprep thereby not allowing scripts to run automatically.
2. It seems that the Administrator account seems to change because I get an error when trying to access the encrypted password file.  I have to start running the Powershell cmdlets from scratch in order for it to work which defeats the automated process, but does join the domain.

I should note that my unattend.xml file changes the Administrator password. (Don't know if that has anything to do with it).

Please advise.
Ivano Viola
System Administrator

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

Join our community to see this answer!
Unlock 2 Answers and 8 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 2 Answers and 8 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