Solved

script to list all users profiles in computers in the active directory

Posted on 2010-09-03
13
1,240 Views
Last Modified: 2012-05-10
i need to collect this information from my client computers in active directory 2003 for example :

Computer Name           Profile
client1                         user1
                                  user2
                                  user3

-------------------------------

also i need the script to get the computers from a text file.and the output  in .csv file.

Thank You
0
Comment
Question by:lovemask
[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
  • 5
  • 4
  • 4
13 Comments
 

Author Comment

by:lovemask
ID: 33601020
if its posible to know each profile size in mb in each computer that will be great.
thanks
0
 
LVL 4

Expert Comment

by:Amnonm
ID: 33601287
Here you go just copy to TXT file customize and later save as .VBS


Const adVarChar = 200
Const MaxCharacters = 255
Const ForReading = 1
Const ForWriting = 2
Const ADS_SCOPE_SUBTREE = 2
Const FOR_WRITING = 2

'************************ Create Server List ****************************

set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("Serverlist.txt") Then
	objFSO.DeleteFile("Serverlist.txt")
End IF
Set objFile = objFSO.CreateTextFile("Serverlist.txt", FOR_WRITING)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
Set RootDse = GetObject( "LDAP://RootDse" )
strADSPath = "LDAP://" & RootDse.get( "DefaultNamingContext" )
objCommand.CommandText = _
	    "Select Name, Location from '" & strADSPath &_
		"' Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    objFile.WriteLine objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop



'***********************  Sort Server List  ******************************

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ComputerName", adVarChar, MaxCharacters
DataList.Open

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("serverlist.txt", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    DataList.AddNew
    DataList("ComputerName") = strLine
    DataList.Update
Loop

objFile.Close

DataList.Sort = "ComputerName"

DataList.MoveFirst
Do Until DataList.EOF
    strText = strText & DataList.Fields.Item("ComputerName") & vbCrLf
    DataList.MoveNext
Loop

Set objFile = objFSO.OpenTextFile("serverlist.txt", ForWriting)

objFile.WriteLine strText
objFile.Close

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 33601293
This should get what you're after...change the first two lines as appropriate for your input/output...
Const ComputerList = "C:\Computers.txt"
Const Output = "C:\Output.csv"
Const hklm=&h80000002

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile(Output)
Dim objFile : Set objFile = objFSO.OpenTextFile(ComputerList)
arrPCs = Split(objFile.ReadAll, vbNewLine)

For Each pc in arrPCs
  strDefProfile = GetProfilePath (pc)
  wscript.echo pc & vbTab & strDefProfile
  Set objFolder = objFSO.GetFolder ("\\" & pc & "\" & Replace(strDefProfile, ":\", "$\") )
  On Error Resume Next
  For each fld in objFolder.SubFolders
    objOut.Writeline pc & "," & fld & "," & fld.Size
  Next
Next

objOut.Close

Function GetProfilePath (strPC)
  strRegKey =  "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
  Dim wmiReg : Set wmiReg =GetObject("winmgmts:\\" & strPC & "\root\default:stdregprov")
  iRet=wmiReg.GetStringValue(hklm, strRegKey, "ProfilesDirectory", strValue)
  If iRet=0 Then
    GetProfilePath = strValue & "\"
  End If
End Function

Open in new window

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 67

Expert Comment

by:sirbounty
ID: 33601299
Oops - didn't refresh.  Sorry about that.
And apparently read it a bit differently...
0
 
LVL 4

Expert Comment

by:Amnonm
ID: 33601303
I've extracted this script from MS Tech Net you can find more in there
http://technet.microsoft.com/en-us/scriptcenter/default.aspx 
0
 
LVL 4

Expert Comment

by:Amnonm
ID: 33601313
About the conversion to CSV later you can find it here very short.
http://www.colinwoodhouse.co.uk/txt-csv.htm
0
 

Author Comment

by:lovemask
ID: 33602121
i am getting error in line 13 second script :

Set objFolder = objFSO.GetFolder ("\\" & pc & "\" & Replace(strDefProfile, ":\", "$\") )
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 33602705
What's the error?  If it's an access denied, you don't have admin permissions...
0
 
LVL 4

Expert Comment

by:Amnonm
ID: 33602984
Do you got the error using what script?
0
 

Author Comment

by:lovemask
ID: 33604621
the two scripts are working fine. thanks.. but i need 1 thing more which is:

for example if the client is down or unreachable .. i need the script to continue test the next client in the list ... ( On Error Resume next ). also if its possible to get the size of each profile.?


thank you
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 33604731
You can just relocate that to the top of the script, and it should work...
It should already get the profile size.
Const ComputerList = "C:\Computers.txt"
Const Output = "C:\Output.csv"
Const hklm=&h80000002

On Error Resume Next

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile(Output)
Dim objFile : Set objFile = objFSO.OpenTextFile(ComputerList)
arrPCs = Split(objFile.ReadAll, vbNewLine)

For Each pc in arrPCs
  strDefProfile = GetProfilePath (pc)
  wscript.echo pc & vbTab & strDefProfile
  Set objFolder = objFSO.GetFolder ("\\" & pc & "\" & Replace(strDefProfile, ":\", "$\") )
  For each fld in objFolder.SubFolders
    objOut.Writeline pc & "," & fld & "," & fld.Size
  Next
Next

objOut.Close

Function GetProfilePath (strPC)
  strRegKey =  "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
  Dim wmiReg : Set wmiReg =GetObject("winmgmts:\\" & strPC & "\root\default:stdregprov")
  iRet=wmiReg.GetStringValue(hklm, strRegKey, "ProfilesDirectory", strValue)
  If iRet=0 Then
    GetProfilePath = strValue & "\"
  End If
End Function

Open in new window

0
 

Author Comment

by:lovemask
ID: 33604844
thank you.. its perfect
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 33605324
Happy to have helped - thanks for the grade. :^)
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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