Solved

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

Posted on 2013-10-29
11
315 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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 count occurrences of each item in an array.

809 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