When running the below VBS function to check if the current user is in a certain Security Group, I get error #500 (Variable is undefined) for the line strGroup = LCase(Join(CurrentUser.MemberOf)).
I have Option Explicit declared in the script, so that is not surprising. However, when I do declare the variable (Dim strGroup), the function stops working and always returns false.
Function is_group_member(group)
Dim objNetwork
Dim objUser
Dim CurrentUser
' Set our default return value
is_group_member = False
' Directory Lookup
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
strGroup = LCase(Join(CurrentUser.MemberOf))
' Set return value to true if the user is in the selected group
If InStr(strGroup, lcase(group)) Then
is_group_member = True
End If
End Function