Verify domain join is successful during OS Deployment

There was a question asked on the forums a couple of days ago about how to verify during the OS Deployment Task Sequence, if the computer failed to join the Active Directory domain or not. I wrote together this little script which will check what domain the computer belongs to and if it isn’t the correct domain name the script will return exit code 1 and the task sequence will fail.

The script must be run after the Setup Windows and Configuration Manager step in the task sequence as the computer will restart after that step and configure the Operating System and join the domain.

To implement it:

  1. Save the script below in a folder and create a package containing the script.
  2. Change the domain name in the script to match your environment
  3. Add a “Run Command Line” step in the Task Sequence after the “Setup Windows and Configuration Manager” step.
  4. Add the following command in the “Run Command Line” step cscript.exe checkdomain.vbs
    Checkdomain
  5. Select the newly created package as then package that the command line should be executed from.

Then you are good to go!

Vbscript Checkdomain.vbs:

'Sample script for checking the domain name during OS Deployment

'http://ccmexec.com
'Kept the wscript.echo lines so it is possible to test it
DomainName = "WORKGROUP"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
If objComputer.Domain = DomainName then
' Wscript.Echo "Domain: " & objComputer.Domain
else
' Wscript.echo "Domain not correct: " & objComputer.Domain
wscript.quit(1)
end if
Next

'Sample script for checking the domain name during OS Deployment

'http://ccmexec.com

'Kept the wscript.echo lines so it is possible to test it

DomainName = "WORKGROUP"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings

If objComputer.Domain = DomainName then

' Wscript.Echo "Domain: " & objComputer.Domain

else

' Wscript.echo "Domain not correct: " & objComputer.Domain

wscript.quit(1)

end if

Next

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *