Help with automating an AD-query and some checks
hi,
i'm sorry "ambiguous" subject way me describe topic :)
i'll try , explain need in words , each statement i'll put below code have that. the goal these queries merge 1 working script can of these things , generate output csv-file or whatever.
so here goes:
i have to:
- query ad pc's in <ou> with a name '*-c'
get-qadcomputer -searchroot <ou> | ?{$_.name -like '*-c'}
- from output want first verify if pc in question online or not, if not > write "offline" or in output file
<code> ? (i know several ways can't seem integrate nicely without f*cking output somehow)
- next, if pc's online, script have check 2 things:
- check ie version of host
{[system.diagnostics.fileversioninfo]::getversioninfo("\\$_\c`$\program files\internet explorer\iexplore.exe") }
but how do host variable to get pumped unc-path ? , how subsequently output decently output file in form like: host,ieversion
- check file , it's timestamp (if modified after 01/01/2012 or not)
get-item -path <path> | select lastwritetime
next, check if created after above date , if yes/no write or b list hostname next it.
i'm quite sure can done 1 foreach-loop i've tried several ways , haven't found 1 yet. therefore i'd love here, because i'm on deadline actually :)
lot helping me out here! (but of teaching me great ps scripting techniques & stuff!)
grtz!
kristof
here's basic framework.
$computers = get-qadcomputer -searchroot <ou> | ?{$_.name -like '*-c'} | select-object -expandproperty name foreach ($computer in $computers) { if (test-connection $computer -count 1 -quiet) { # code check ie version # code check file version etc. } else { write-host "$computer offline" } }
grant ward, a.k.a. bigteddy
Windows Server > Windows PowerShell
Comments
Post a Comment