3

I have a powershell script that runs Install-ADDSForest to set up a lab environment. The script is actually run via VMware tools. During the Install-ADDSForest process, the Windows server (2012) will restart, which is fine. And I can wait for VM tools to become available again before proceeding with the next parts of my scripting (install software etc), but the vmware guest operations agent becomes available while Windows is still in its limbo "Please Wait" state, before a login screen appears. However the next steps in the script rely on the domain actually existing.

How can I tell (from a powershell script) whether Windows is fully running? Specifically that the startup changes from Install-ADDSForest have completed, or at least that the logon screen is showing?

AnotherHowie
  • 206
  • 3
  • 13

1 Answers1

0

If you can move the reboot to the end of the VMware script, then you could use the -NoRebootOnCompletion:$true parameter and reboot at the end.

Else, you can check the logfile using the -LogPath <String> parameter to check when it's finished.

There's no reliable way to know when the system is at the login screen. The best way is to check for the availability of services. I use this to check if systems are ready:

While (!(Test-WSMan -Computername <computername> -ErrorAction SilentlyContinue)) {"Waiting for winrm...";sleep 1}
spacenomyous
  • 1,319
  • 7
  • 15
  • No, the domain needs to actually exist before the next bit. Looks like winrm just starts up as part of the normal start up process, but before the AD build stuff has finished. I got it to repeatedly dump Get-Process during startup, and it looks like watching for TrustedInstaller to exit might be my answer. – AnotherHowie Nov 15 '17 at 15:38
  • That's perfect. TrustedInstaller is a Service that runs on demand and you can use the Get-Service cmdlet checking the status instead of returning all the processes. Try this Get-Service -Name TrustedInstaller – spacenomyous Nov 15 '17 at 15:57