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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.