Add-Computer fails to run just after server is sysprep'd


I've developing a PowerShell 3 script to automate the deployment of a XenApp Windows 2008 image to a Hyper-V 2013 host. The basic steps are this:

  1. Create and boots VM - script goes into wait loop for 15 mins
  2. VM boots and sysprep runs. One of the steps is to run a PowerShell script to rename the computer (but leave on a workgroup) and reboot
  3. After the 15 minute wait, the script loops until the new VM has a valid IP address (via DHCP)
  4. It then runs the following command to add the computer to the domain

Add-Computer -ComputerName $VMIP -DomainName "" -LocalCredential $LocalCredential -Credential $DomainCredential -Verbose -Restart

This fails with following error:

Add-Computer : Cannot establish the WMI connection to the computer '' with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).

The credentials are constructed using the following type of command:

$DomainCredential = New-Object System.Management.Automation.PsCredential "FQ-DomainName\", $DomainPassword)

Run the same command again manually immediately and it fails. If one then waits for a significant time (say 30 mins maybe - don't know exactly) and run the command, it works.

First thoughts somehow were the firewall so I turned that off and recreated the image. No difference.

Another thought was that the original gold VM before if was sysprep'd was in the domain and had group policy applied to it. When the new VM boots and syspreps, it's not on the domain and I'm unsure what state that previous group policy which have on the server. Possibly a red herring.

It's almost as if the machine kind of isn't ready for RPC but that it sorts itself out after a time - but a long time in the scheme of things. I can understand services not been quite ready after boot but not 15+ minutes.

I guess what I'm looking for here is either and magic anwswer (!) or tips on debugging the RPC server and the mechanism Add-Computer uses to attempt to get the machine to join the domain.

asked on Server Fault Feb 6, 2014 by Rob Nicholson

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0