Link to home
Start Free TrialLog in
Avatar of janhoedt
janhoedt

asked on

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

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
		)
	)
)
Avatar of Xaelian
Xaelian
Flag of Belgium image

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.
Avatar of janhoedt
janhoedt

ASKER

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.
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
I'll post a new item for this.
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 }
}
Please see my post: "I'd need to extract the members of an ad group (pc's), then query the version of Internet explorer."
Avatar of oBdA
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

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.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial