Powershell Report on Number of Client PCs in Forest by Internet Explorer Version

Hi,

I want to create a script that queries all client PCs in our forest (All running XP) and reports into a CSV/Excel sheet) what browser version they are running e.g. Internet Explorer 5/6/7/8. The report is only focused on Internet Explorer stats.

Is this possible with Powershell, VB Script, Javascript, Batch file?

Cheers,
Fin
LVL 1
cpadmAsked:
Who is Participating?
 
jawa29Commented:
Hi cpadm

This script should help you with what you want to do.

Jawa29
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2

On Error Resume Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'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,IE Version" & 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 oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHostname & "\root\default:StdRegProv")
		oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue
		
		sTxt = sTxt & sHostname & "," & sValue & 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:\IE_Version_Results.csv", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close

Open in new window

0
 
cpadmAuthor Commented:
Hi jawa29, I kicked off this script on Friday morning at around 10am (GMT). It was still running this morning at 10am, so that's not good! It's hard to say exactly what's wrong, as the text output file isn't produced until the loop has completed and there were no errors showing that something had gone wrong. We have a relatively large forest, but it should not take more than 4-5 hours to contact all machine accounts in AD...
0
 
jawa29Commented:
Hi cpadm

I have rejiged the script so the text file is created first then edited all the way through.

Jawa29
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2

On Error Resume Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'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

Set oFSO = CreateObject("Scripting.FileSystemObject")
sTxt = "Hostname,IE Version" & vbCrLf
Set oTextFile = oFSO.OpenTextFile("C:\IE_Version_Results.csv", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close
'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 = sHostname & ",SWITCHED OFF" & vbCrLf
	Else
		'PC is Alive
		Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHostname & "\root\default:StdRegProv")
		oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue
		
		sTxt = sHostname & "," & sValue & vbCrLf
	End If
	
	Set oTextFile = oFSO.OpenTextFile("C:\IE_Version_Results.csv", ForWriting, True)
	oTextFile.WriteLine(sTxt)
	oTextFile.Close
	
	oRS.MoveNext
Loop

Open in new window

0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
jawa29Commented:
Sorry ignore code above forgot to change the text file to append once it had been created.

Jawa29
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2
Const ForAppending = 8

On Error Resume Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'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

Set oFSO = CreateObject("Scripting.FileSystemObject")
sTxt = "Hostname,IE Version" & vbCrLf
Set oTextFile = oFSO.OpenTextFile("C:\IE_Version_Results.csv", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close
'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 = sHostname & ",SWITCHED OFF" & vbCrLf
	Else
		'PC is Alive
		Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHostname & "\root\default:StdRegProv")
		oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue
		
		sTxt = sHostname & "," & sValue & vbCrLf
	End If
	
	Set oTextFile = oFSO.OpenTextFile("C:\IE_Version_Results.csv", ForAppending, True)
	oTextFile.WriteLine(sTxt)
	oTextFile.Close
	
	oRS.MoveNext
Loop

Open in new window

0
 
cpadmAuthor Commented:
Thanks

Currently, i modified the script to add in the root of our domain in the following line:

vDomain = oRoot.Get("DefaultNamingContext")

where I changed "DefaultNamingContext" to "myRootDomain.local".

To limit the scanning of AD, can this be modified to point at the OU level?

0
 
jawa29Commented:
You should be able to change the LDAP query as follows:

oCommand.CommandText = "<LDAP://OU=ThirdLevel,OU=SecondLevel,OU=FirstLevel," & vDomain & ">;(&(!userAccountControl:1.2.840.113556.1.4.803:=65536)((objectCategory=Computer)));cn;Subtree"

Jawa29
0
 
cpadmAuthor Commented:
Hi Jawa29,

I've modified the LDAP location as suggested, and modified the CSV file location in the script, but nothing else. I added in 2 Msgbox print statements to track the values of the vars sHostname and sTxt, to see the data as the script loops, but both of the Msgbox's contents are always empty, and the text added to the CSV file is also empty...

I've attached the code - Is there something else I should be modifying?
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2
Const ForAppending = 8

On Error Resume Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'Get the current domain name
Set oRoot = GetObject("LDAP://RootDSE")
vDomain = oRoot.Get("xDomain.yDomain.rootDomain.local") 

'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://OU=Standard,OU=Desktop,OU=Computers,OU=myCountry," & vDomain & ">;(&(!userAccountControl:1.2.840.113556.1.4.803:=65536)((objectCategory=Computer)));cn;Subtree"
Set oRS = oCommand.Execute

Set oFSO = CreateObject("Scripting.FileSystemObject")
sTxt = "Hostname,IE Version" & vbCrLf
Set oTextFile = oFSO.OpenTextFile("C:\Scripts\IE_Version_Results.csv", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close
'Page through each computer found
Do While Not oRS.EOF
	sHostname = oRS("cn")
	Msgbox sHostname 'This always outputs a black box
	'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 = sHostname & ",SWITCHED OFF" & vbCrLf
	Else
		'PC is Alive
		Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHostname & "\root\default:StdRegProv")
		oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue
		
		sTxt = sHostname & "," & sValue & vbCrLf
		Msgbox sTxt 'This always outputs a black box
	End If
	
	Set oTextFile = oFSO.OpenTextFile("C:\Scripts\IE_Version_Results.csv", ForAppending, True)
	oTextFile.WriteLine(sTxt)
	oTextFile.Close
	
	oRS.MoveNext
Loop

Open in new window

0
 
cpadmAuthor Commented:
Just laughing at my comment typos above... The 2 Msgbox's are blank, and not black!
0
 
jawa29Commented:
It doesn't like this line
vDomain = oRoot.Get("xDomain.yDomain.rootDomain.local")

I changed it back to the one I supplied and it works.
vDomain = oRoot.Get("DefaultNamingContext")  - this should always get the pc running the script local domain.

Jawa29
0
 
cpadmAuthor Commented:
In the end, I adapted Sean Kearney's Powershell script as my solution:

http://gallery.technet.microsoft.com/scriptcenter/6b8163d1-5fae-43b5-a664-a2d1f6e1e2da

$COMPAREDATE=GET-DATE 
$CSVFileLocation='C:\TEMP\OldComps_180.CSV' 
GET-QADCOMPUTER -SearchRoot "ou=xxx,ou=yyy,ou=zzz,dc=aaa-core,dc=bbb,dc=ccc" -SearchScope Subtree -SizeLimit 0 -IncludedProperties LastLogonTimeStamp | where { ($CompareDate-$_.LastLogonTimeStamp).Days -gt $NumberDays } | Select-Object Name, LastLogonTimeStamp, OSName, ParentContainerDN | Sort-Object ModificationDate, Name | Export-CSV $CSVFileLocation 

Open in new window


This allowed me to point the query directly to the OU level as opposed to scanning the whole AD forest.
0
 
cpadmAuthor Commented:
Thanks for your help jawa29!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.