Earlier today I got an email from a fellow deployment geek struggling with getting a VBScript application wrapper for MDT to work. He wanted to install the app, but only of the machine was joined to the domain.
Now, if you review the ZTIDomainJoin.wsf script, you find a ready-made function to do just that, the IsMemberOfDomain function. So to solve the problem you just use that function in the application script.
Here is a download for the completed script.
Below is the IsMemberOfDomain function in the ZTIDomainJoin.wsf script.
Function IsMemberOfDomain ( sDomain ) Dim oComputer IsMemberOfDomain = False for each oComputer in objWMI.InstancesOf("Win32_ComputerSystem") Select Case oComputer.DomainRole Case 0, 2 exit function Case 1, 3, 4, 5 oLogging.CreateEntry "Check Win32_ComputerSystem.DomainRole = "& oComputer.DomainRole & " For Domain: " & oComputer.Domain, LogTypeInfo ' Optionally we can test to see if we are allready in a specific domain. IsMemberOfDomain = Instr( 1, oComputer.Domain , sDomain, vbTextCompare ) <> 0 exit function Case else oLogging.CreateEntry "Unknown value for Win32_ComputerSystem.DomainRole = " & oComputer.DomainRole, LogTypeWarning End Select Next oLogging.CreateEntry "Unknown Domain Status (Win32_ComputerSystem did not return any instances).", LogTypeWarning End function
You can also do the check in PowerShell, of course:
if ((Get-WmiObject win32_computersystem).partofdomain -eq $true) { # Machine is domain joined } else { # Machine is not domain joined }/ Johan
More ...