?
Solved

script needed to check all machines for service pack level

Posted on 2011-09-27
10
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 36708946
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 8

Expert Comment

by:jawa29
ID: 36708967
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 36709037
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
ID: 36709155
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
 
LVL 8

Expert Comment

by:jawa29
ID: 36709218
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
ID: 36709220
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
ID: 36709268
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 2000 total points
ID: 36709335
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
ID: 36709394
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

770 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