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

VN:F [1.9.4_1102]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.4_1102]
Rating: 0 (from 0 votes)

Here’s the second script of today.
It is a mutation of the previous script.
Added is a depth limit, this is done by a second argument of the subroutine.
The subroutine needs two arguments: the path of the folder and the depth level.
The path can be local (“c:\temp”) or an UNC path like “\\server\test”.

Follow the next steps to run the script (admin rights needed on the folder you want to enumerate):

  • open your favorite text editor
  • copy and paste the script into the editor
  • change the path of the folder to your folder path
  • change the depth value to your depth value (current value = 2)
  • save the script (for example c:\temp\enumeratesubfolderslevel.vbs)
  • open a command prompt
  • go to “c:\temp”
  • give “cscript enumeratesubfolderslevel.vbs” (without quotes) and enter

The script:

' Name : enumeratesubfolderslevel.vbs
' Description : script to enumerate the subfolders (recursive) with depth limit
' Author : dirk adamsky - deludi bv
' Version : 1.01 corrected small counter error
' Date : 05-03-2010
' Level : Intermediate

ViewSubFolders "c:\temp", 2
Sub ViewSubFolders(strFolder, strMaxLevel)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(strFolder)
	If strMaxlevel >= 1 Then
		For Each SubFolder in objFolder.SubFolders
			Wscript.Echo SubFolder.Path
			ViewSubFolders SubFolder, (strMaxlevel - 1)
		Next
	End If
	Set objFolder = Nothing
	Set objFSO = Nothing
End Sub

When you have problems/questions please make a reply, when you like the script please rate it with the star rating below.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

VN:F [1.9.4_1102]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.4_1102]
Rating: 0 (from 0 votes)

The motto of the day is: Recursion rules.
A couple of years ago I have done quite a few Filesystem Object scripts.
To refresh my mind I have made some new filesystem scripts.
This is the first one: a simple subroutine that uses recursion to enumrate all subfolders of a folder.
The subroutine needs one argument: the path of the folder.
The path can be local (“c:\temp”) or an UNC path like “\\server\test”.

Follow the next steps to run the script (admin rights needed on the folder you want to enumerate):

  • open your favorite text editor
  • copy and paste the script into the editor
  • change the path of the folder to your folder path
  • save the script (for example c:\temp\enumeratesubfolders.vbs)
  • open a command prompt
  • go to “c:\temp”
  • give “cscript enumeratesubfolders.vbs” (without quotes) and enter

The script:

' Name : enumeratesubfolders.vbs
' Description : script to enumerate all subfolders (recursive) of a given folder
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 05-03-2010
' Level : Intermediate

ViewSubFolders "c:\temp"
Sub ViewSubFolders(strFolder)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(strFolder)
	For Each SubFolder in objFolder.SubFolders
		Wscript.Echo SubFolder.Path
		ViewSubFolders SubFolder
	Next
	Set objFolder = Nothing
	Set objFSO = Nothing
End Sub

When you have problems/questions please make a reply, when you like the script please rate it with the star rating below.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

VN:F [1.9.4_1102]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.4_1102]
Rating: 0 (from 0 votes)

Okido, here’s my first powershell script (or command line).

The action I want to accomplish is to copy a file to another directory.
I installed powershell v2 on my machine.

To open the powershell prompt you can do next steps:

  • give ‘windows key + r’ (opens ‘Start=>Run’)
  • give ‘powershell’ without the quotes
  • the powershell prompt now opens

When you want to change the working directory give cd followed by the full path, for example ‘cd c:\temp’ (without quotes).

After changing the working directory it is time for action.
In ‘c:\temp’ I created a file named ‘test.txt’ and a directory called ‘c:\temp\test’.
The powershell command to copy ‘test.txt’ to the ‘test’ directory is:


copy-item c:\temp\test.txt c:\temp\test

The result is that the file test.txt is copied to c:\temp\test\test.txt.
Instead of using copy-item you can also use the aliases ‘cp’ or ‘cpi’.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

VN:F [1.9.4_1102]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.4_1102]
Rating: 0 (from 0 votes)

This script is for reporting purposes.
It enumerates the members of a specified group and calculates the number of files that each user has on his/her homedirectory. It is especially useful when run from the scheduler.

Follow the next steps to run the script (no admin rights needed):

  • open your favorite text editor
  • copy and paste the script into the editor
  • change the distinguished name of the group to your specific situation
  • save the script (for example c:\temp\groupfilesonhomedirectory.vbs)
  • open a command prompt
  • go to “c:\temp”
  • give “cscript groupfilesonhomedirectory.vbs” (without quotes) and enter

The script:

' Name : groupfilesonhomedirectory.vbs
' Description : script to count the number of files on homedirectory for groupmembers
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 26-01-2010

Set objGroup = GetObject("LDAP://CN=test,OU=test,DC=test,DC=org")
For Each M in objGroup.Members
	If M.homeDirectory <> "" Then
		FileCnt = 0
		ReturnFileCountUsingFSO M.homeDirectory, FileCnt
		WScript.echo M.cn & " ; " & M.homeDirectory & " ; " & FileCnt & " files on home directory"
	End If
Next
Set objGroup = Nothing

Function ReturnFileCountUsingFSO(strPath, FileCnt)
	On Error Resume Next
	Set FSO = CreateObject("scripting.filesystemobject")
	Set fld = FSO.GetFolder(strPath)
	FileCnt = FileCnt + fld.Files.Count
	For Each f In fld.SubFolders
		ReturnFileCountUsingFSO f.path, FileCnt
	Next
	Set f = Nothing
	Set fld = Nothing
	Set FSO = Nothing
End Function
VN:F [1.9.4_1102]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.4_1102]
Rating: 0 (from 0 votes)
© 2010 Dirk Adamsky Scripting Blog Suffusion WordPress theme by Sayontan Sinha