'List users from specific groups
Good morning all,
I am currentlycovering my line manager. And I need to modify an existing to VBScript, to pull users from specific groups in AD (Commercial, Finance, HR, IT, Marketing, Operations, and Property):
Const ForReading = 1,ForWriting = 2,ForAppending = 8
StartFilename = "AD groups.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(StartFilename,ForAppending, True)
strDomainName = inputbox("Enter Domain Name","AD Billing","")
Set objDomain = GetObject("WinNT://" & strDomainName)
For each objDomainObject in objDomain
If objDomainObject.class = "Group" Then
Set objGroup = GetObject("WinNT://"& strDomainName & "/" & objDomainObject.Name)
objTextFile.writeline("")
objTextFile.writeline("Domain: " & strDomainName & " Group: " & objDomainObject.Name)
objTextFile.writeline("")
Set objMemberList = objGroup.Members
For Each objGroupMember In objMemberList
Set objMember = objGroupMember
objTextFile.writeline ("Group member: " & objMember.Name)
Next
End If
Next
objTextFile.close
Any help is greatly appriciated Kind regards
Justin
Solution 1:[1]
Just add another If
after the If
where you find out that it's a Group
, but instead of comparing on the class
, compare on the `Name.
So amending your original code it would be something like this:
Const ForReading = 1,ForWriting = 2,ForAppending = 8
StartFilename = "AD groups.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(StartFilename,ForAppending, True)
strDomainName = inputbox("Enter Domain Name","AD Billing","")
strGroupName = inputbox("Enter Group Name","AD Billing","")
Set objDomain = GetObject("WinNT://" & strDomainName)
For each objDomainObject in objDomain
If objDomainObject.class = "Group" Then
If objDomainObject.Name = strGroupName Then
Set objGroup = GetObject("WinNT://"& strDomainName & "/" & objDomainObject.Name)
objTextFile.writeline("")
objTextFile.writeline("Domain: " & strDomainName & " Group: " & objDomainObject.Name)
objTextFile.writeline("")
Set objMemberList = objGroup.Members
For Each objGroupMember In objMemberList
Set objMember = objGroupMember
objTextFile.writeline ("Group member: " & objMember.Name)
Next
End If
End If
Next
objTextFile.close
I assumed that you wanted to ask each time which group using a InputBox
, otherwise you could hardcode those values in the If
statement asIf objDomainObject.Name = "Commercial" Or objDomainObject.Name = "Finance" Or .... Then
Solution 2:[2]
You are missing this above the next statement (To reenumerate the objects after being in a container/OU.):
If objDomainObject.Class = "organizationalUnit" Or
objDomainObject.Class = "container" Then
enumMembers (objMember)
End If
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hans Olsson |
Solution 2 | JBL |