Link to home
Create AccountLog in
Avatar of skdcsupport
skdcsupport

asked on

Microsoft Windows XP Pro rollout

I have been rolling out XP Pro upgrade on pcs with 2000 on, is it possible to write a script to run over the network to find out what pcs still have Windows 2000 installed thanks.
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, do you have Active Directory?  If so, save the code below into a text file and save it with a VBS extension.  It will get the Operating System as recorded by the Active Directory and output to a file those machine names with Windows 2000.

Regards,

Rob.
strOutputfile = "Win2k_Machines.txt"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 ' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
 
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
 
strFilter = "(&(objectClass=computer)(operatingSystem=*2000*))"
strAttributes = "adsPath,cn"
 
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
 
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
strDetails = "Computers with Windows 2000 installed."
Do Until adoRecordset.EOF
	strDetails = strDetails & VbCrLf & Mid(adoRecordset.Fields("cn").Value, 4)
    ' Move to the next record in the recordset.
    adoRecordset.MoveNext
Loop
 
' Clean up.
adoRecordset.Close
Set adoRecordset = Nothing
 
adoConnection.Close
 
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
 
WScript.Echo "Done. Please see " & strOutputFile

Open in new window

Whoops, got that wrong, please change this line (on line 30):
strDetails = strDetails & VbCrLf & Mid(adoRecordset.Fields("cn").Value, 4)

to this
strDetails = strDetails & VbCrLf & adoRecordset.Fields("cn").Value

Regards,

Rob.
Avatar of skdcsupport
skdcsupport

ASKER

That worked fine thank you but I have a lot of workstations that are still listed in Active Directory that are not currently on our network.

Is it possible to change the script to output to a text file when the user log's onto to their pc?
Yes, you can do that.  I was originally going to do that, but figured that some machines may not be turned on for a while, but I guess if you keep an eye on the output files, you'll eventually catch them all.

Try this.....you need to set up a network share such as \\server\win2k_os$ and then change this line to suit:
strSharePath = "\\server\win2k_os$"

then set this script as a login script, and what will happen is that as people log in, if they are using Windows 2000 a text file will be placed in that share with a name of their computer name.

So, keep watching that share, and once you've upgraded the OS, delete the file.

This will only look for Microsoft Windows 2000 Professional installations at the moment.

Regards,

Rob.
strSharePath = "\\server\win2k_os$"
 
If Right(strSharePath, 1) <> "\" Then strSharePath = strSharePath & "\"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
strComputer = "VM09790RINGW2k"
strOutputFile = strSharePath & strComputer & ".txt"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strOutputFile) = False Then
	Set objWMIService = GetObject("winmgmts:" _
		& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
	Set colSystemInfo = objWMIService.ExecQuery _
		("Select * from Win32_OperatingSystem",,48)
	For Each objItem In colSystemInfo
		strOS_Caption = "Caption: " & objItem.Caption
	Next
	MsgBox strOS_Caption
	If strOS_Caption = "Microsoft Windows 2000 Professional" Then
		Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
		objOutputFile.Close
		Set objOutputFile = Nothing
	End If
End If
Set objFSO = Nothing
Set objNetwork = Nothing

Open in new window

Oh, remove this line, it was only for my testing....
strComputer = "VM09790RINGW2k"

Rob.
Rob,

Thanks for the script, I tried it but unfortunately is doesnt give me the output in a text file. Instead it pops up a dialog box on the screen telling me what version of windows Im running.

I have attached a print screen shot of the message.

Thanks

Luke


ERROR.jpg
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account