Kaseya Community

If query - User In AD Group/OU?

This question is answered

I'm looking for the possibility to check if the user is a member of a domain group before executing the rest of the script.

Everything in kaseya is designed around machines, and machine groups. I want to create a policy and some scheduled scripts based on logged in user information.

 

The only IF statement i've located is "IF User Name Logged in" then...

Problem is I cannot build scripts around 500+ users, all needing their own tweaks and install scripts.

 

Any one made this possible thru WMI or equal?

Regards,
Nicklas

Verified Answer
  • Here's an edited VBScript that will find the user's domain and login name and then check to see if they're in a particular group (which you'll need to edit). There's several threads here with info on how to return the result to Kaseya - you could write the info into a file, for instance, and then read it into a Kaseya variable. There's also info on how to prompt for the group name and then pass that group name to the vbscript as a script parameter, if you wish.

    Dim objWSH, strUser, objUser, objGroup, WSHNetwork, strUserDomain

    set WSHNetwork = Server.CreateObject("WScript.Network")

    set objWSH = Server.CreateObject("WScript.Shell")

    'Get the user's domain

    strUserDomain = objWSH.ExpandEnvironmentStrings( "%USERDOMAIN%" )

    'Get the user's login name

    strUser = WSHNetwork.UserName

    'Get the list of groups the user belongs to 

    Set objUser = GetObject("WinNT://strUserDomain/" & strUser)

    For Each objGroup in objUser.Groups

    'Check to see if the user is in a particular group

    If (UCase(objGroup.Name) = UCase("This_Group_Name")) Then

    MsgBox(strUser & " is in the group)

    End if

    Next



    [edited by: zippo at 8:09 AM (GMT -7) on 10-5-2011] Fix another error
All Replies
  • Here's a simple VBScript. You'll need to modify the domain name as needed and the group names but you get the idea, anyway:

    Dim objWSH, User, objUser, objGroup, WSHNetwork

    set WSHNetwork = Server.CreateObject("WScript.Network")

    set objWSH = Server.CreateObject("WScript.Shell")

    User = WSHNetwork.UserName

    Set objUser = GetObject("WinNT://DOMAIN_NAME/" & User)

    For Each objGroup in objUser.Groups

    If (UCase(objGroup.Name) = UCase("This_Group_Name")) Or (UCase(objGroup.Name) = UCase("That_Group_Name")) Then

    Wscript.Echo("User in the groups)

    Exit For

    Else

    Wscript.Echo("User NOT in the groups)

    End if

    Next



    [edited by: zippo at 9:51 AM (GMT -7) on 10-4-2011] Fix spelling
  • Can you make this script dynamic, so that it will use current domain (logged on user)?

    I also need some way to evaluate the result, and send it back to the procedure.

    Thanks,

    Nicklas

  • Here's an edited VBScript that will find the user's domain and login name and then check to see if they're in a particular group (which you'll need to edit). There's several threads here with info on how to return the result to Kaseya - you could write the info into a file, for instance, and then read it into a Kaseya variable. There's also info on how to prompt for the group name and then pass that group name to the vbscript as a script parameter, if you wish.

    Dim objWSH, strUser, objUser, objGroup, WSHNetwork, strUserDomain

    set WSHNetwork = Server.CreateObject("WScript.Network")

    set objWSH = Server.CreateObject("WScript.Shell")

    'Get the user's domain

    strUserDomain = objWSH.ExpandEnvironmentStrings( "%USERDOMAIN%" )

    'Get the user's login name

    strUser = WSHNetwork.UserName

    'Get the list of groups the user belongs to 

    Set objUser = GetObject("WinNT://strUserDomain/" & strUser)

    For Each objGroup in objUser.Groups

    'Check to see if the user is in a particular group

    If (UCase(objGroup.Name) = UCase("This_Group_Name")) Then

    MsgBox(strUser & " is in the group)

    End if

    Next



    [edited by: zippo at 8:09 AM (GMT -7) on 10-5-2011] Fix another error