[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

enumberating a dictionary to a text file in VBScript

Posted on 2013-06-18
3
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
cantoris earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

650 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