Home » vbscript

VBScript to find old users in a domain

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject(”ADODB.Connection”)
Set objCommand = CreateObject(”ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
Set objDSE = GetObject(”LDAP://RootD
SE”)
strDomain = objDSE.Get(”DefaultNamingContext”)
objCommand.CommandText = “SELECT adspath,Name FROM ‘LDAP://” & strDomain & “‘ ” & “WHERE objectClass=’user’ and objectcategory=’person’ and lastlogontimestamp <=’00000000000′”
objCommand.Properties(”Page Size”) = 2000
objCommand.Properties(”Timeout”) = 30
objCommand.Properties(”Searchscope”) = ADS_SCOPE_SUBTREE
objCommand.Properties(”Cache Results”) = […]

How to get IP Address Information from Network Adapters Using Vbscript

The following Vbscript will gather Ip address information from network cards:
Set objWMIService = GetObject(”winmgmts:\\”& strComputer & “\root\cimv2″)
Set colAdapters = objWMIService.ExecQuery (”SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”)
n = 1
For Each objAdapter In colAdapters
wIELine
WriteLineBoldIE “Network Adapter Info”
wIETableHeaderStart “100″
wIERowStart
wIETableHeaderItem “Adapter”
wIETableHeaderItem “IP”
wIETableHeaderItem “Subnet”
wIETableHeaderItem “Gateway”
wIETableHeaderItem “DNS”
wIETableHeaderItem “WINS”
wIERowStop
If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
wIERowStart
If i=0 Then
wIERowItem “Adapter […]

How do I Disable Windows Product Activation Notices with VBscript?

If you are interested in disabling the Windows product activation notices with a vbscript then the following steps maybe of interest to you:

In the root of your system drive save the following in a text file
Set objWMI = GetObject(”winmgmts:{impersonationLevel=
impersonate}!\\” & computer & “\root\cimv2″)Set objWPA = objWMI.ExecQuery(”Select * from
Win32_WindowsProductActivation”)
For Each PA in objWPA
PA.SetNotification(0)
Next
Replace computer with […]

How do I script the unlocking of domain user accounts?

To use this script you will need to enter the relevant username and domain into message boxes that prompt.
UserName = InputBox(”Enter the user’s login name that you want to unlock:”)
If UserName = “” Then
WScript.Echo “No username was given or you clicked Cancel”
WScript.Quit(1)
End If
DomainName = InputBox(”Enter the domain name in which the user account exists:”)
If […]

How do I Remotely Shutdown all Domain Computers -VBscript

If you every need to shutdown all you domain computers due to a expected power outage, security breach etc. then this Vbscript should help:
On Error Resume Next
Set objNet = CreateObject(”wscript.network”)
strCurrentPC = objNet.ComputerName
‘The following section will connect to any Active Directory domain
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject(”ADODB.Connection”)
Set objCommand = CreateObject(”ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active […]

How do I Remotely Terminate all Windows Terminal Server Sessions with Vbscript?

‘ This vbscript finds all active Terminal Server sessions on server HOST defined
‘ below and terminates them. Does not terminate the
‘ current session if being run remotely.
‘ If running on local host, set HOST value to “.”
HOST = “.”
‘ Get disconnected sessions and log them off
sessions = DisconnectedSessions(HOST)
For each session in sessions
TerminateWinSession HOST, sessionId
Next
‘ […]

How do I disable Inactive Active Directory User Accounts with Vbscripting?

If you are a system administrator managing an Active Directory environment and you need to disable inactive user accoutns then the following vbscript may assist:
‘Queries AD for all WIndows domain accounts inactive for 12 weeks or more and disables these accounts
dsquery user -inactive 12 | dsmod user -disabled yes
‘Queries AD for all active directory […]

Vbscript to check the system time and time zone on a domain computer

===========================================================
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set arrComputers = GetObject _
(”LDAP://cn=computers, dc=domain, dc=local”)
arrComputers.Filter = Array(”Computer”)
For Each objItem In arrComputers
strComputer = objItem.CN
WScript.Echo
WScript.Echo “==========================================”
WScript.Echo “Computer: ” & strComputer
WScript.Echo “==========================================”
Set objWMI = GetObject(”winmgmts:\\” & strComputer & “\root\cimv2″)
WScript.Echo “Time zone is:”
Set colTZ = objWMI.ExecQuery(”select * from Win32_TimeZone”)
For Each objTZ in colTZ
Wscript.Echo vbTab & objTZ.Caption
Next
Set objWMIService = […]