Solved

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

Posted on 2013-10-29
11
316 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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 84

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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