Archive

Archive for the ‘Scripting’ Category

Quick way to find hotfix installation status

I know there are varioud menthods for finding the hotfix installation status, but I felt this as very easy one.

To find the hotfix installation status on local machine:

wmic qfe where hotfixid=”KB958644″ list full

To find on a remote machine:

wmic /node: qfe where hotfixid=”KB958644″ list full

To find on list of machines:

o Place all machines into a text file(machine.txt)
o Run the below batch file

=== File name: get-hotfix-status.bat ===

echo off
for /f “tokens=* delims= ” %a in (test.txt) do wmic/Node:%a qfe where hotfixid=”KB958644″ list full

=== End of file ===

Please comment if you know any better way.

Happy Learning,
Sitaram Pamarthi,

Categories: Know your Shell, Scripting

Script to generate last logon time of all users

January 21, 2009 1 comment

SBelow code give the last logon time of all users in active directory. Please drop me a mail, if you want any further fine tuning to this script or incase of queries.

I am providing this script without any warranty. Use at your own choice. :-)

Code:

############# Getlastlogon.vbs ################

on error resume next

Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Open “Provider=ADsDSOObject;”

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

objCommand.CommandText = _
“<LDAP://dc=mydomain,dc=com>;” & _
“(&(objectCategory=person)(objectClass=user));” & _
“ADsPath;subtree”

Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
strADsPath = objRecordset.Fields(“ADsPath”)
Set objUser = GetObject(strADsPath)
set objLogon = objUser.Get(“lastLogonTimestamp”)
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo “Approx last logon timestamp for ” & strADsPath & intLogonTime + #1/1/1601#
objRecordset.MoveNext
Wend
objConnection.Close
##################################

Note: you can redirect the script output from command prompt to clipboard by using http://www.sitaram-pamarthi.com/2009/01/copy-command-output-to-clip-board.html

Syntax: cscript Getlastlogon.vbs clip

Happy Learning…
Sitaram Pamarthi

Categories: Scripting