Solved

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

Posted on 2013-10-29
11
312 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
 

Author Comment

by:janhoedt
ID: 39608061
I'll post a new item for this.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 83

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now