Solved

script needed to check all machines for service pack level

Posted on 2011-09-27
10
252 Views
Last Modified: 2012-05-12
hi

i need a script that will produce a report of all of the computers in a W2K3 AD domain and list the service pack installed on each workstation.  All workstations are running windows xp.

Please help this is an urgent requirement.

Thanks experts
0
Comment
Question by:richardstuartpowell
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
I would suggest to use for that DS Tools to export workstations to a text file and the use PsInfo, which can be downloaded from
http://technet.microsoft.com/en-us/sysinternals/bb897550

DS Tools run on a DC or workstation with Administrative Tools Installed

dsquery * -filter "&(&(objectClass=Computer)(objectCategory=Computer))" -limit 0 -attr sAMAccountName >c:\comps.txt

Remove "sAMAccountName" line from text file and remove leading spaces. Open file in notepad and press Ctrl+H
Find what press <space>
Replace with "do not put anything"
Press "Replace All" and save
Create empty directory on C-Drive "comps"

now use

for /f %i in (c:\comps.txt) do PsInfo "ServicePack" \\%i >c:\comps\%i.log

and that's all :)

Regards,
Krzysztof
0
 
LVL 11

Expert Comment

by:X_layer
Comment Utility
0
 
LVL 8

Expert Comment

by:jawa29
Comment Utility
Hi

Try this script. It will take awhile to run but the results should be what you want.

This can also be expanded to include other infomation about the PCs.

Jawa29
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2

On Error Resume Next

'Get the current domain name
Set oRoot = GetObject("LDAP://RootDSE")
vDomain = oRoot.Get("DefaultNamingContext") 

'Create an LDAP connection to Active Directory
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand =   CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 1000

'Query AD for non disabled computers
oCommand.CommandText = "<LDAP://" & vDomain & ">;(&(!userAccountControl:1.2.840.113556.1.4.803:=65536)((objectCategory=Computer)));cn;Subtree"
Set oRS = oCommand.Execute

sTxt = "Hostname,OS,ServicePack" & vbCrLf
'Page through each computer found
Do While Not oRS.EOF
	sHostname = oRS("cn")
	
	'Ping PC to see if it's Live!
	Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
		
	i=0
	Do Until i = 2
		Set cPings = oWMIService.ExecQuery("Select * From Win32_PingStatus where Address = '" & sHostname & "'")

		For Each oStatus in cPings
		    If IsNull(oStatus.StatusCode) or oStatus.StatusCode <> 0 Then 
				sPing = 0 
		    Else
		        sPing = 1
		        Exit For
		    End If
		Next
		i = i +1
	Loop
	
	'Set text based on Ping result
	If sPing = 0 Then
		'PC is switched OFF!
		sTxt = sTxt & sHostname & ",SWITCHED OFF," & vbCrLf
	Else
		'PC is Alive
		Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHostname & "\root\cimv2")
		Set colOSes = oWMIService.ExecQuery("Select * from Win32_OperatingSystem")
			For Each objOS in colOSes
				sOS = objOS.Caption
				sSP = objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
			Next
		sTxt = sTxt & sHostname & "," & sOS & "," & sSP & vbCrLf
	End If
	
	oRS.MoveNext
Loop

'Write text file when all Computers have been checked
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile("C:\OS_SP_Results.csv", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close

Open in new window

0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Sorry missed space in syntax :)

should be:
for /f %i in (c:\comps.txt) do PsInfo "Service Pack" \\%i >c:\comps\%i.log

Krzysztof
0
 
LVL 2

Author Comment

by:richardstuartpowell
Comment Utility
Thanks very much jawa29 - I am running the script now.

I take it I have to wait for the script to complete before the text file gets created?

OK, waiting ... What else could we check for with this bad boy?

Rich.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Expert Comment

by:jawa29
Comment Utility
Hi Rich

Text file created once script is complete.

You can check anything you like!! Once you've made a connection to the remote PC you can check Hardware, Software, Registry entries etc...

Jawa29
0
 
LVL 2

Author Comment

by:richardstuartpowell
Comment Utility
jawa29:

script worked perfectly (thanks!) - a couple of questions:

1) what can we add and also report on
2) how could i automate this via GP so that when users log on / reboot or logoff it re-audits their workstation and updates a spreadsheet?

thanks
0
 
LVL 8

Expert Comment

by:jawa29
Comment Utility
In answer to question 1 What do you want to know? I don't think I've found anything I can't get.

To automate this script through GP just add it to the Machine start-up/shutdown script, you could also have the data populating a database. you will need to make a slight change to it as in the below code. The first script I supplied gets the computer accounts from AD where as this one below will only work on the PC it is being run on.

Jawa29
Const ForWriting = 2

On Error Resume Next
'Get OS information
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOSes = oWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
	sOS = objOS.Caption
	sSP = objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
Next
	sTxt = sTxt & sHostname & "," & sOS & "," & sSP & vbCrLf
End If

'Write text file
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile("C:\OS_SP_Results.txt", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close

Open in new window

0
 
LVL 8

Accepted Solution

by:
jawa29 earned 500 total points
Comment Utility
Hi Rich

I thought I'd put together some good resources for you.

First get yourself vbsedit http://www.vbsedit.com/ it comes with loads of samples that you can play with.

Second have a look round http://blogs.technet.com/b/heyscriptingguy/ nowadays you have to trawl through all the powershell stuff but there are some good vbs bits to be found. also here http://www.w3schools.com/vbscript/default.asp a good resources too.

Hope all this helps
Jawa29
0
 
LVL 2

Author Closing Comment

by:richardstuartpowell
Comment Utility
you are awesom man, your script worked perfectly I have just asked another question - look for it and you will find it - I am hoping you will respond to this as well as you obviously know what you are doing!

OK I will check the resources you suggested but to be honest I've never been that interested in scripting (I'm more of a VMware man myself!) I'd rather ask the top experts such as yourself :-)

Rich.

Full points awarded my friend :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now