We help IT Professionals succeed at work.
Get Started

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

13,761 Views
Last Modified: 2012-05-11
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 http://bsonposh.com/archives/338).  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 af.org -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.
Comment
Watch Question
System Administrator
Commented:
This problem has been solved!
Unlock 2 Answers and 8 Comments.
See Answers
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