Install an MDT application, but only if machine is domain joined

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 complete 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               
    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

About the author

Johan Arwidmark

0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
10 years ago

Thanks, not sure why I hadn't thought of that since I'm using something similar to restrict certain software from installing if no CD/DVD drive exists.
So if you want something to install if it's not on the domain you can use "SELECT * FROM Win32_ComputerSystem WHERE PartOfDomain = False"

10 years ago

Nice tip, thanks!

/ Johan

10 years ago

You could also put a WMI query on the install application step:

select * from Win32_Computersystem where partofdomain = 0