Solved

enumberating a dictionary to a text file in VBScript

Posted on 2013-06-18
3
249 Views
Last Modified: 2013-06-27
I have a need here at work to create a text file of the currently logged in user (at login) that would enumberate the groups the user is a member of and write it to a text file. I have a function I use to enumerate the groups, but I do not know how to read the dictionary itself and write those values to a text file. Here is the function I use at logon to identify the groups;

Function IsMember(sGroup)
 Dim sAdsPath, oUser, oGroup
 If IsEmpty(oGroupDict) Then
     Set oGroupDict         = CreateObject("Scripting.Dictionary")
     oGroupDict.CompareMode = vbTextCompare
     sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
     Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
     For Each oGroup In oUser.Groups
         oGroupDict.Add oGroup.Name, "-"
     Next
     Set oUser = Nothing
 End If
 IsMember = CBool(oGroupDict.Exists(sGroup))
End Function

Any help would be appreciated
0
Comment
Question by:Akish1960
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
cantoris earned 500 total points
ID: 39260359
Here's the sort of thing you could use.

strOutputFilePath = "C:\GroupsList.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFilePath, True)
For Each strKey In oGroupDict.Keys
   objOutputFile.WriteLine strKey
Next
objOutputFile.Close

Open in new window

0
 

Author Comment

by:Akish1960
ID: 39263632
thank you. i will try this out and comment or accept soon.
0
 

Author Closing Comment

by:Akish1960
ID: 39282633
So I put it into the function, as follows, and it works as advertised. Thank you so much for your help.

Function IsMember(sGroup)
Dim sAdsPath, oUser, oGroup

strOutputFilePath = strShare & "\" & strComputer & "_group.log"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = oFSO.CreateTextFile(strOutputFilePath, True)
 
 If IsEmpty(oGroupDict) Then
     Set oGroupDict         = CreateObject("Scripting.Dictionary")
     oGroupDict.CompareMode = vbTextCompare
     sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
     Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
     For Each oGroup In oUser.Groups
         oGroupDict.Add oGroup.Name, "-"
     Next
     For Each strKey In oGroupDict.Keys
    objOutputFile.WriteLine strKey
      Next
      objOutputFile.Close
     Set oUser = Nothing
 End If
 IsMember = CBool(oGroupDict.Exists(sGroup))
End Function
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now