Solved

Export pc's of AD group to file then query for Internet explorer version

Posted on 2013-10-29
11
317 Views
Last Modified: 2013-11-26
Hi,

I'd need to extract the members of an ad group (pc's), then query the version of Internet explorer.

Version of IE, is covered, but howto extract pc's of AD group?
Please advise
J.

@echo off
setlocal
set ComputerFile=serverlist.txt
set LogFile=Results.csv
if exist "%LogFile%" del "%LogFile%"
for /f %%a in ('type "%ComputerFile%"') do (
	ping -4 -n 2 %%a | find /i "TTL" >NUL
	if errorlevel 1 (
		echo %%a: OFFLINE
		>>"%LogFile%" echo %%a,OFFLINE
	) else (
		for /f "tokens=2*" %%i in ('reg.exe query "\\%%a\HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v "version" ^| find /i "Version"') do (
			echo %%a: %%j
			>>"%LogFile%" echo %%a,%%j
		)
	)
)
0
Comment
Question by:janhoedt
[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
11 Comments
 
LVL 13

Expert Comment

by:Xaelian
ID: 39608036
Const FileName ="domaincomputers.csv"
set cmd = createobject("ADODB.Command")
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")

cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn

set objRoot = getobject("LDAP://RootDSE")

cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;(objectCategory=Computer);" & _
		  "name,operatingsystem,operatingsystemservicepack, operatingsystemversion;subtree"
'**** Bypass 1000 record limitation ****
cmd.properties("page size")=1000

set rs = cmd.execute
set objFSO = createobject("Scripting.FileSystemObject")
set objCSV = objFSO.createtextfile(FileName)

q = """"

while rs.eof <> true and rs.bof <> true
	objcsv.writeline(q & rs("name") & q & "," &  q & rs("operatingsystem") & q & _
		"," & q & rs("operatingsystemservicepack") & _
		q & "," & q & rs("operatingsystemversion") & q)
	rs.movenext
wend

objCSV.Close
cn.close

wscript.echo "Finished"

Open in new window


Here you go.
0
 

Author Comment

by:janhoedt
ID: 39608052
Thanks, but I was looking for a simple powershell. If I run your script, I get a list of pc's with info I don't need.
As mentioned, I need to run a query to a certain AD group, then have version of Internet Explorer. Appreciate your input but your script doesn't help me.
0
 

Author Comment

by:janhoedt
ID: 39608056
Something like this
Get-ADGroupmember -Identity "mygroup" | out-file c:\scripts\members.txt

then I'd need to filter on pc-name only and query those pc's for Internet explorer
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:janhoedt
ID: 39608061
I'll post a new item for this.
0
 
LVL 13

Expert Comment

by:Xaelian
ID: 39608154
Do you want to get the computers from a specific OU, or what do you mean with group member? If you want it from an OU: replace the values and voila.

$ou = [ADSI]"LDAP://OU=YourOU,DC=Microsoft,DC=COM"
foreach ($child in $ou.psbase.Children) {
    if ($child.ObjectCategory -like '*computer*') { Write-Host $child.Name }
}
0
 

Author Comment

by:janhoedt
ID: 39608909
Please see my post: "I'd need to extract the members of an ad group (pc's), then query the version of Internet explorer."
0
 
LVL 85

Expert Comment

by:oBdA
ID: 39610894
This is your original script, with additional code to create the server list dynamically by group membership. If the variable "Group" is empty, the old logic will still be active. It uses the good old "net group /domain" command which should be present on any windows OS, so no special requirements (except maybe that "net group" queries a global group; if your group is a "domain local", you need to change "net.exe group" to "net.exe localgroup" in line 11.) It does not recurse, so direct group membership is required.
@echo off
setlocal enabledelayedexpansion
set ComputerFile=serverlist.txt
set LogFile=Results.csv
set Group=Domain Computers

if "%Group%"=="" goto EndGroupQuery
set ComputerFile=%temp%\serverlist.tmp
if exist "%ComputerFile%" del "%ComputerFile%"
set Collect=0
for /f "tokens=1-3" %%a in ('net.exe group "%Group%" /domain') do (
	set Account1=%%~a
	set Account2=%%~b
	set Account3=%%~c
	if "!Account1:~0,10!"=="----------" (
		set Collect=1
	) else (
		if "!Collect!"=="1" (
			for %%p in (1 2 3) do (
				if "!Account%%p:~-1!"=="$" (
					>>"%ComputerFile%" echo !Account%%p:~0,-1!
				)
			)
		)
	)
)
:EndGroupQuery

if exist "%LogFile%" del "%LogFile%"
for /f %%a in ('type "%ComputerFile%"') do (
      ping -4 -n 2 %%a | find /i "TTL" >NUL
      if errorlevel 1 (
            echo %%a: OFFLINE
            >>"%LogFile%" echo %%a,OFFLINE
      ) else (
            for /f "tokens=2*" %%i in ('reg.exe query "\\%%a\HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v "version" ^| find /i "Version"') do (
                  echo %%a: %%j
                  >>"%LogFile%" echo %%a,%%j
            )
      )
)

Open in new window

0
 

Author Comment

by:janhoedt
ID: 39618750
What's wrong with Powershell? It's the new way to go and I have already half of the command. Appreciate the input, but it's old code.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39665711
Try..
Import-Module Activedirectory
Get-ADGroupMember "Computer Group" | 
	?{$_.objectClass -eq "computer"} | 
		select -ExpandProperty Name | % {
$Server = $_
Try {
	$hklm = 2147483650
	$key = "SOFTWARE\Microsoft\Internet Explorer"
	$value = "Version"
	$wmi = [wmiclass]"\\$Server\root\default:stdRegProv"
	Write-Host "Collecting information from Computer $Server" -ForegroundColor Green
		New-Object PSObject -Property @{
		Computer = $Server
		"IE Version" = 	($wmi.GetStringValue($hklm,$key,$value)).svalue
		}
	}
	Catch [Exception]{
	Write-Host "Collecting information from Computer $Server - Error : $($_.Exception.Message)" -ForegroundColor Red
		New-Object PSObject -Property @{
		Computer = $Server
		"IE Version" = "Error : $($_.Exception.Message.Trim())"
		}
	}
} | Select Computer,"IE Version" | 
Export-Csv C:\IEReport.csv -NoTypeInformation

Open in new window

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

717 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