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.10 (changed script error based on input from Jim)
' Date : 06-05-2011
' 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 = 0 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.!
Great work and really appreciated.
Will this script export profile size for users running Vista OS? These profiles will have .V2 extension and while running the above script it exported all but with no size. Please find below the output sample:
\\{file server name}\profiles\{userlogonname} ; {Last Name, First Name}; {email address}; MB
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.
Hi, thanks for the script. I used it in my demo environment, but it doesn’t show the profile path. Win 2003 native domain with a couple of testusers. Profile paths and TS Profile paths are entered in AD.
Any idea why it doesn’t work for me ?
Edwin
Hi Edwin,
The profilepath and the ts profile path are 2 separate attributes of a user object.
MS advices not to use the same path for the both of them.
The script above does not check for TS profile path values.
Can you cut and paste the profile path of your first testuser (for example \srv001profilesuser001).
Please paste the UNC path in the Start=>Run and see if the UNC path exists.
Best regards,
Dirk Adamsky
I too am not seeing the profile path displayed in the output. It is just blank. Interestingly, the size of the profile is displayed accurately, so I know the path exists. I am using 2008R2 for my AD. Any idea?
Hi Jim,
do you see displayname and mail attributes in the output?
Yes, I see everything except the ProfilePath. Not sure if something is different in 2008 R2. Have you tried this on R2?
Hi Jim,
I have tested the script: it’s not a 2003 vs 2008 issue.
You have found an error in my script.
The 1 in line 32 has to be a 0 (arrays start counting with 0).
I have changed the script, it now also returns the profilePath value.
Best regards,
dirk adamsky
Used this, works brilliantly.
Thanks a lot.
Where exactly would I add my output path to the script?
Hi Mike,
the output of the script normally is ‘on screen’.
You can pipe the output to a text file.
When you have the script in c:\temp the command is:
cscript roamingprofilesize.vbs > roamingprofilesize.txt
The output then goes to the txt file instead of the screen.
Dirk Adamsky
Can you paste any example of the output?
I am looking for something similar to this:
“computer name” “user profile name” “size of my documents” “my documents folder path”
Hi Mike,
I will you a custom script tomorrow.
Dirk Adamsky
Hi Mike,
A roaming profile is mostly stored on a server.
The ‘my documents’ folder is included in the roaming profile except when the folder is rerouted to another network location (f.e. home share).
The location of the ‘my documents’ folder is not in Active Directory but in the user profile (ntuser.dat).
It is not possible to get that data with the script above.
What you can do to get the data is add some code to your loginscript.
Can you tell me if you use kixtart or vbscript for your loginscript?
Dirk Adamsky
kixtart. However, my network admin rather not touch the login script. So I have a shared UNC folder all workstations can read/write too. I was hoping to drop the .vbs script in that folder. Then run a command on my workstation, which would call from a list that contains all the workstations in the domain. Take this list and instead of a queue, since all workstations can access the UNC, go out at the same time to each workstation and have the workstation gather the information, then update a csv or xml file, which will contain all the file information for each workstation. (i.e., profile name ( win 7 and win xp clients), main directory folder sizes like my documents, last login date and time for each profile)
Hi Mike,
I forgot to ask: do you use local or roaming profiles in your network?
Dirk Adamsky
Hi Dirk,
We use local profiles.
Thanks!
Hi Mike,
Thanks.
I can make a script that enumerates all workstations in AD, then connects to each workstation with WMI and get the requested profile and my documents info.
The results will be written to a share.
I can make the script on monday.
Regarding the lastlogon info: I already have a script for that, maybe it’s possible to include it with the script above.
Dirk Adamsky
Hi Dirk,
Thank You, this sounds perfect.
If some user profiles are on multiple workstations and since each user profile is local and not roaming, how will that affect the output? Also, since we are calling the user profiles from Active Directory, if certain workstations have multiple user’s on one workstation will this affect the output, or just append the same .csv file.
[...] script is made for Mike. He asked for a script to enumerate all local profiles and their size of the computers in his [...]
Hi Mike,
I have made the script for you to get the local profiles and their size.
The script can be found here:
http://vbscriptblog.com/vbscript/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/
Please let me know if it’s ok for you.
Best regards,
dirk adamsky
[...] all AD users, their home directories and the size of them. I already had the script to do that for roaming profiles. This script is a mofified [...]
Hi Dirk,
How can we make this to work on a list of users? I was trying to write a script which will get the profile path of each user and verify couple of folders in that profile path. If those folders were not found then i have to query the last logon time for that user. Could you please help.
Many thanks!!