Skip to content


Enumerate All Empty Active Directory Groups

Enumerate All Empty Active Directory Groups

The following script was created to enumerate all the empty groups that exist in an Active Directory.

This output of the script can be piped to a text file.

Basic steps are
1) Create connection to Active Directory domain
2) Create recordset from query, filtering in only empty groups
3) Enumerate through recordset, displaying name of group
4) Cleanup

* * * * * * * * * * Start of GetEmptyADGroups.vbs * * * * * * * * * *

Option Explicit

On Error Resume Next

Dim objCommand
Dim objConnection
Dim objRootDSE
Dim strDNSDomain
Dim strBase
Dim objSystemInfo
Dim strDomain
Dim strFilter
Dim strAttributes
Dim strQuery
Dim objRecordset
Dim strGroupName

Set objCommand = CreateObject(“ADODB.Command”)
Set objConnection = CreateObject(“ADODB.Connection”)

objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject(“LDAP://RootDSE”)

strDNSDomain = objRootDSE.Get(“defaultNamingContext”)
strBase = “”

Set objSystemInfo = CreateObject(“ADSystemInfo”)
strDomain = objSystemInfo.DomainShortName

strFilter = “(&(objectCategory=group)(!member=*))”

strAttributes = “sAMAccountName”

strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”
objCommand.CommandText = strQuery
objCommand.Properties(“Page Size”) = 100
objCommand.Properties(“Timeout”) = 30
objCommand.Properties(“Cache Results”) = False

Set objRecordset = objCommand.Execute

Do Until objRecordset.EOF
strGroupName = objRecordset.Fields(“sAMAccountName”).Value
WScript.Echo strGroupName
objRecordset.MoveNext
Loop

objRecordset.Close
objConnection.Close

Set objRecordset = Nothing
Set objSystemInfo = Nothing
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objCommand = Nothing

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: GetEmptyADGroups.zip (697 B)

* * * * * * * * * * End of GetEmptyADGroups.vbs * * * * * * * * * *

Posted in Scripts.

Tagged with , , , .


Recreate DNS Hosts From Export File Into a Microsoft DNS Server

Recreate DNS Hosts From Export File Into a Microsoft DNS Server

The following script was created to add hosts, from a list of exported hosts and IPs originally from a unrelated DNS server’s zone, into the specified Microsoft DNS server’s DNS zone.

The basic usage of the script is:
CScript AddDNSHost.vbs /DNSServer:DNSServer /DNSZone:DNSZone /HostName:HostName /HostIP:HostIP
And an example:
AddDNSHost.vbs /DNSServer:192.168.0.1 /DNSZone:DNSZone.local /HostName:MyComputer /HostIP:192.168.1.123

A very simple way of constructing multiple commands can be achieved with practically any speadsheet application where column A holds the list of host names, column B holds their respected IP addresses and column C the following command (starting from row 1):

=”AddDNSHost.vbs /DNSServer:192.168.0.1 /DNSZone:DNSZone.local /HostName:” & A1 & ” /HostIP:” & B1
The above command can be copied once for each row.

The resulting constructed command can then be directly pasted into a command prompt

‘* * * * * * * * * * * Start of AddDNSHost.vbs * * * * * * * * * * *

On Error Resume Next

strDNSServer = Wscript.Arguments.Named(“DNSServer”)
strDNSZone = Wscript.Arguments.Named(“DNSZone”)
strHostName = Wscript.Arguments.Named(“HostName”)
strHostIP = Wscript.Arguments.Named(“HostIP”)

If Len(Trim(strDNSServer)) > 0 And Len(Trim(strDNSZone)) > 0 And Len(Trim(strHostName)) > 0 And Len(Trim(strHostIP)) > 0 Then
If Right(UCase(strHostName), Len(strDNSZone) + 1) “.” & UCase(strDNSZone) Then
strHostName = strHostName & “.” & strDNSZone
End If
intRecordClass = 1
intTTL = 600

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\MicrosoftDNS”)
Set objItem = objWMIService.Get(“MicrosoftDNS_AType”)
intReturn = objItem.CreateInstanceFromPropertyData(strDNSServer, strDNSZone, strHostName, intRecordClass, intTTL, strHostIP)
If Err.Number = 0 And intReturn = 0 Then
WScript.Echo strHostName & vbTab & “Added”
Else
WScript.Echo strHostName & vbTab & “Failed”
End If
End If

‘* * * * * * * * * * * Start of AddDNSHost.vbs * * * * * * * * * * *

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: AddDNSHost.zip (641 B)

Posted in Scripts.

Tagged with , , , .


Enumerate All Active Directory Users’ ProxyAddresses

Enumerate All Active Directory Users’ ProxyAddresses

The following script was created to enumerate all the various addresses an Active Directory users might have.

This output of the script can be piped to a text file which in turn can be imported into a database to generate various reports.

Basic steps are
1) Create connection to Active Directory domain
2) Create recordset from query, filtering in only user accounts
3) Enumerate through recordset, display combination of sAMAccountName and proxyAddress
4) Cleanup

* * * * * * * * * * Start of GetproxyAddresses.vbs * * * * * * * * * *

Option ExplicitOn Error Resume Next

Dim objCommand
Dim objConnection
Dim objRootDSE
Dim strDNSDomain
Dim strBase
Dim objSystemInfo
Dim strDomain
Dim strFilter
Dim strAttributes
Dim strQuery
Dim objRecordset
Dim strUserName
Dim strCN
Dim objUser
Dim arrproxyAddresses
Dim strproxyAddresses

Set objCommand = CreateObject(“ADODB.Command”)
Set objConnection = CreateObject(“ADODB.Connection”)

objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject(“LDAP://RootDSE”)

strDNSDomain = objRootDSE.Get(“defaultNamingContext”)
strBase = “”

Set objSystemInfo = CreateObject(“ADSystemInfo”)
strDomain = objSystemInfo.DomainShortName

strFilter = “(&(objectCategory=Person)(objectClass=User))”

strAttributes = “sAMAccountName,cn,proxyAddresses”

strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”
objCommand.CommandText = strQuery
objCommand.Properties(“Page Size”) = 100
objCommand.Properties(“Timeout”) = 30
objCommand.Properties(“Cache Results”) = False

Set objRecordset = objCommand.Execute

Do Until objRecordset.EOF
strUserName = objRecordset.Fields(“sAMAccountName”).Value
strCN = objRecordset.Fields(“cn”).value
arrproxyAddresses = objRecordset.Fields(“proxyAddresses”).value
If IsArray(arrproxyAddresses) = True Then
For Each strproxyAddresses In arrproxyAddresses
WScript.Echo strUserName & vbTab & strproxyAddresses
Next
End If
objRecordset.MoveNext
Loop

objRecordset.Close
objConnection.Close

set objUser = Nothing
Set objRecordset = Nothing
Set objSystemInfo = Nothing
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objCommand = Nothing

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: GetproxyAddresses.zip (818 B)

* * * * * * * * * * End of GetproxyAddresses.vbs * * * * * * * * * *

Posted in Scripts.

Tagged with , , , .


DoesServiceExist – Detect if service exist on remote host

 DoesServiceExist – Detect if service exist on remote host

This script can be used to detect whether or not a service exist on a remote host.
I originally created it to determine if WDS is installed (ServiceName = WDSServer)

Usage: CScript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME

Example: CScript.exe //nologo DoesServiceExist.vbs /Computer:CompanyServer01 /ServiceName:WDSServer

Option Explicit

On Error Resume Next

Dim strComputer
Dim strServiceName
Dim objComputer
Dim objService

strComputer = Wscript.Arguments.Named(“Computer”)
strServiceName = Wscript.Arguments.Named(“ServiceName”)

If Len(Trim(strComputer)) > 0 And Len(Trim(strServiceName)) > 0 Then
If IsOnline(strComputer) = True Then
Set objComputer = GetObject(“WinNT://” & strComputer & “,computer”)

If Err.Number = 0 Then
Set objService = objComputer.GetObject(“service”, strServiceName)

If Err.Number = 0 Then
WScript.Echo strComputer & vbTab & “Services Status” & vbTab & “Exists”
Else
WScript.Echo strComputer & vbTab & “Services Status” & vbTab & “Does not exist”
End If
Else
WScript.Echo strComputer & vbTab & “Services Status” & vbTab & “Unknown”
End If
Else
WScript.Echo strComputer & vbTab & “Services Status” & vbTab & “Offline”
End If
Else
WScript.Echo “Usage: cscript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME”
End If

Function IsOnline(strComputer)
Dim objPing
Dim objStatus

Set objPing = GetObject(“winmgmts:” & Chr(123) & “impersonationLevel=impersonate” & Chr(125) & “”).ExecQuery(“select * from Win32_PingStatus where address = ‘” & strComputer & “‘”)

For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode0 Then
‘Nothing
Else
IsOnline = True
End If
Next
End Function

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: DoesServiceExist.zip (707 B)

Posted in Scripts.

Tagged with , , .


InstallWDS – Installing Windows Deployment Services (WDS) from a batch file

Installing Windows Deployment Services (WDS) from a batch file

I needed to install WDS on 300+ servers but found that the server build did not have a local copy of OS setup or service pack files. I also wanted to set the paths back to the original values.

I started by adding all files required by WDS to the DFS and I created the following batch file.

@ECHO OFF

REG EXPORT “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup” %WINDIR%\InstallWDS.reg /y
REG ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup” /v “SourcePath” /t REG_SZ /d “\\SERVERNAME\SHARE” /f
REG ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup” /v “ServicePackSourcePath” /t REG_SZ /d “\\SERVERNAME\SHARE” /f

VER | Find “Microsoft Windows [Version 5.2." > nul
If %ERRORLEVEL% == 0 GoTo Win2003
VER | Find "Microsoft Windows [Version 6.0." > nul
If %ERRORLEVEL% == 0 GoTo Win2008

GoTo CleanUp

:Win2003
ECHO [Components] > %WINDIR%\InstallWDS.inf
ECHO RemInst = on >> %WINDIR%\InstallWDS.inf
Sysocmgr.exe /i:sysoc.inf /u:%WINDIR%\InstallWDS.inf
GoTo CleanUp

:Win2008
ServerManagerCmd -install WDS
GoTo CleanUp

:CleanUp
REG IMPORT %WINDIR%\InstallWDS.reg
DEL %WINDIR%\InstallWDS.inf
DEL %WINDIR%\InstallWDS.reg

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: InstallWDS.zip (480 B)

Posted in Scripts.

Tagged with , , , .


GetRegionalSettings – Remotely get the country value of a host’s regional settings

GetRegionalSettings by Shaun Vermaak is a script to remotely get the country value of a host’s regional settings

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: GetRegionalSettings.zip (626 B)

Usage: CScript GetRegionalSettings.vbs /Computer:HOSTNAME

Posted in Scripts.

Tagged with , .


MoveSysvol – Automate the relocation of the Sysvol folder

MoveSysvol automated by Shaun Vermaak is a batch to automatically relocate the Sysvol folder as per http://support.microsoft.com/kb/842162

The following must be in the working folder or in path:
MoveSysvol.bat
SetFRS.vbs
sysvol.inf
linkd.exe (Not included)
robocopy.exe (Not included)

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: MoveSysvol.zip (1.66 KB)

Usage: MoveSysvol.bat OLDSYSVOLPATH NEWSYSVOLPATH DOMAINFQDN
Example: MoveSysvol.bat C:\Windows\SYSVOL D:\SYSVOL TESTDOMAIN.COM

Posted in Scripts.

Tagged with , .


CommandThreader – Execute any list of commands threaded into as many threads as needed (Updated)

CommandThreader by Shaun Vermaak is a command line tool that makes it possible to execute any list of commands threaded into as many threads as needed.

03/05/2009 – Fixed thread IDs
24/11/2008 – Added line numbers
03/11/2008 – Minor bug fixes

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: CommandThreader.zip (7.05 Kb)

Usage: CommandThreader.exe NUMBER_OF_THREADS INPUT_FILE.TXT
Lines in INPUT_FILE.TXT must be in format COMMAND|ARGUMENT|WORKING_DIRECTORY|HIDDEN|TIMEOUT

Example: PSEXEC.exe|\\192.168.0.1 -c -d -f Program.exe||True|1000

Posted in Development.

Tagged with , .


SetDevicePath – Automates the building of the DevicePath variable in registry from a specified path

SetDevicePath by Shaun Vermaak is a script to automatically build the DevicePath variable in registry from a specified path
. Very useful in SysPrep process (Replaces OEMPnpDriversPath in SysPrep.inf)

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: SetDevicePath.zip (1.09 KB)

Usage: CScript SetDevicePath.vbs /DriverFolder:PATHTODRIVERS

Posted in Scripts.

Tagged with , , .


GenStr – Random string generator

GenStr by Shaun Vermaak generates random strings for passwords and pre-share keywords

Usage: GenStr.exe Aag1! LENGTH COUNT
A = Generate string with only A,B,C,D,E,F (UPPERCASE affects whole string)
a = Generate string with only a,b,c,d,e,f (lowercase affects whole string)
g/G = Include alphabetical in generated string
1 = Include numerics in generated string
Exclamation = Include special characters
LENGTH = Length of generated string
COUNT = Number of strings to generate

Publishers website: http://www.ittelligence.co.za
ITtelligence mirror: GenStr.zip (6.08 Kb)

Posted in Development.

Tagged with , .