| Active Directory: VBscript to enumerate the last logon of all AD users and a lot of user attributes V2 | Active Directory: VBscript to enumerate all Active Directory published printers |
For a sysadmin roaming profiles are both a blessing and a curse.
In time they tend to grow and grow…
The roaming profile size problem results in: long logon and logoff times, corrupted profiles, etc.
This script enumerates the roaming profile size of all users in your Active Directory domain.
By adding extra attributes to the arrAttributes array you can change the output.
Follow the next steps to run the script (admin rights needed for access to the roaming profiles directory):
* open your favorite text editor
* copy and paste the script into the editor
* save the script (for example c:\temp\roamingprofilesize.vbs)
* open a command prompt
* go to “c:\temp”
* give “cscript roamingprofilesize.vbs” (without quotes) and enter
The script:
' Name : roamingprofilesize.vbs
' Description : script to enumerate the roaming profile size of all users in Active Directory
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 15-03-2010
' Level : intermediate
arrAttributes = Array("profilePath","displayname","mail")
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
Set objRootDSE = Nothing
strFilter = "(&(objectCategory=person)(objectClass=user)(profilePath=*))"
strAttributes = Join(arrAttributes,",")
Wscript.Echo Join(arrAttributes,";") & " ; roaming profile size in MB"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
On Error Resume Next
strTempOutput = ""
For i = 1 To Ubound(arrAttributes)
strTempOutput = strTempOutput & " ; " & adoRecordset.Fields(arrAttributes(i)).Value
strOutput = Mid(Ltrim(strTempOutput),3)
Next
Wscript.Echo strOutput & " ; " & Foldersize (adoRecordset.Fields(arrAttributes(0)).Value) & " MB"
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
Function Foldersize(strPath)
On Error Resume Next
Set objFSO = CreateObject("scripting.filesystemobject")
Set objFld = objFSO.GetFolder(strPath)
Foldersize = Round(objFld.Size/1048576,2)
Set objFld = Nothing
Set objFSO = Nothing
End Function
When you have problems/questions please post a reply. Also can alo give a ‘star’ rating.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV





Great script man. Exactly what I needed to make our CIO happy.!
Hi.. Great script thanks. I can see the “set objRootDSE” binds to the domain root. How Can I set this to connec to a specific OU and just check the roaming profiles for the users in the OU?
Thanks Damien
Hi Damien,
That can be done bij changing line 17 to something like:
strBase = “”
Change the DN to your specific DN.
Best regards,
Dirk Adamsky
Deludi BV
Hi Dirk
Thanks for quick response.
I can see line 17 is strBase = “”
Which part do I replace. I tried a few combinations but got errors on script.
I have been trying to run the report on a DN as follows
OU=ANYOU,DC=our,DC=domain,DC=com
Thanks Damien
Hi Damien,
I thought I made a cut and paste error but it turns out that WordPress does not like the brackets….
line 17 should then become:
Best regards,
Dirk Adamsky
Hi
Thanks for this.. Thought I had tried this, Tried again and it works
Sweet.
Thanks again.