Skip navigation

Monthly Archives: November 2012

The Belcher’s have officially moved into our new home, bought our new home, and have the interwebs back in our possession.

I’ve been spending a fair amount of time with CM12 now for work, and hopefully once my personal life dies down a bit, and I start getting back into a normal flow I’ll get some interesting CM12 content posted.

Until then!

 

I’ve updated the inventory enforcement script and post for anyone who utilizes it. It should be cleaner now as it only depends on wmi for the inventory actions.

Here’s the link back.

So in an attempt to quickly extract OS version and Service Pack for a few machines in an environment the idea was presented to pull the data from active directory. The properties exist so the logic seemed sound; and as we’ve discussed this before it’s a pretty easy task with the active directory module in PowerShell, and here’s the code:

$list = gc computers.txt
Import-Module ActiveDirectory
ForEach($item in $list){
                $ado = (get-adcomputer $item -Properties *)
                $pso = New-Object PSObject
$pso | Add-Member -Name "Computer Name" -MemberType NoteProperty `
		-Value $ado.CN
$pso | Add-Member -Name "Operating System" -MemberType NoteProperty `
		-Value $ado.OperatingSystem
$pso | Add-Member -Name "Service Pack" -MemberType NoteProperty `
		-Value $ado.OperatingSystemServicePack
$pso
}

Assuming for the sake of example the name of this script is, get-adservicepack.ps1, and you’ve got your computers.txt file with your computer names in it then we’d run it like this.

./get-adservicepack.ps1 | export-csv -NoTypeInformation MyAdOutput.csv

So what’s happening?

First, we’re taking the get-content command to pull data from a local text file “computers.txt” into a data object and then iterating through it sequentially.  We are then using the computer name as the lookup name with the get-adcomputer cmdlet along with all it’s ad properties and assign it to a variable called ado.

Now we create a PowerShell object and begin to give it some noteproperties with values pulled from our ad object we created from the ad cmdlet then echo it’s contents out by calling it.

When we run the script and pipe it’s output to export-csv –NoTypeInformation we are taking that output and putting it directly into a csv without any of the object information, otherwise it’s a tabled console output.

PowerShell is so boss sometimes…

Maybe we just do all this in one line?

gc computers.txt|ForEach-object{Get-ADComputer $_ -properties *|select -Property name,operatingsystem,operatingsystemservicepack}|export-csv -notypeinformation output.csv

Scroll that line, like a boss.

Gallery entry on Script Center if you want to rate it

So my free time has been spent lately helping with 2 children with walking pneumonia, 1 infant (perfectly healthy) working a full time job with more than a full time workload; and a lot of the cool, fun stuff I’m doing at work (in my opinion anyway)…. I can’t talk about here

.:: sadface ::.

(I still think my wife has been working harder than I have)

Trick or treating was fun, both Will and Maggie had a blast at their last Trunk or Treat @ HSBC, and run around their neighborhood.  Will was all go, all night; and Maggie was super fired up about her candy!  I was exhausted afterwards of course, but I was overjoyed to see their excitement!  Glad I got to TC this week.

As far as my gaming; I’ve been able to play a little bit of Borderlands 2 (not even 20 yet), and Torchlight 2 (wiped out my save so had to start over) which I have enjoyed.  AC3 was released, and Halo 4 is coming next Tuesday.  Alas, my consoles are packed for the move so I won’t be getting/playing them right away which pains me a bit.  I’d get AC3 for PC, but I have already played all the others on my PS3, so I wish to maintain that trend.

And for coding; I’ve been doing a fair amount of (windows) scripting lately, but nothing really ground breaking.  I did write a SQL to email script in both vbscript then re-wrote in PowerShell (since I was informed CDO will be depreciated in future releases of exchange) which I plan on sharing here in another post once I’ve scrubbed them.  They are actually jokingly easy to do, but very useful for anyone that hasn’t got a paid tool for this kind of thing.

In the short term I’m going to share a simple script to quickly gather OS service pack information from AD from a list of machines and dump it to a csv I wrote for a buddy of mine (seriously, in PowerShell this is crazy simple).

Expect to see that post around Monday or Tuesday; until then, have a good one and pray for us (or keep us in your thoughts).  There’s a lot going on, and we all feel a bit overwhelmed.