richardstuartpowell
asked on
script needed to check all machines for service pack level
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
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
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
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
Sorry missed space in syntax :)
should be:
for /f %i in (c:\comps.txt) do PsInfo "Service Pack" \\%i >c:\comps\%i.log
Krzysztof
should be:
for /f %i in (c:\comps.txt) do PsInfo "Service Pack" \\%i >c:\comps\%i.log
Krzysztof
ASKER
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.
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.
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
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
ASKER
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
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 :-)
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 :-)
http://technet.microsoft.com/en-us/sysinternals/bb897550
DS Tools run on a DC or workstation with Administrative Tools Installed
dsquery * -filter "&(&(objectClass=Computer)
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