SCAPaoT

System Center, Automation, Powershell and other Thoughts

Tag Archives

Hashtable doesn’t contain a method ‘Ádd’

The powershell has a really nice implementation of a dictionary. It is called Hashtable and can be used to store pairs of keys and values.
Compared with the dictionary used in vbscript, it is really simple to use,
and I have used it several times befor. Till last friday:

There is a method called ‘Add’, really!
And running a get-member agains a hashtable shows at the first entry:

Name         MemberType      Definition
—-              ———-                 ———-
Add            Method                  System.Void Add(System.Object key, System.Object value)

So where the hell does this error come from.
I decided to make a set-psdebug -step in the powershell ISE.
Have a look what I’ve found:

Yes, you can trust your eyes, there is an acute accent on top of the A
Add -> Ádd

Ok, so where are my glasses:

As you can see, using the ISE with a Font Size of 12
and a sceen resolution of 1920 x 1200
makes it hard to see everything clear.

And I’m really glad, that this wasn’t a real bug to my favorite object hashtable.

Get the IPAddresses from all computers in your Active Directory

A colleague of mine asked, how to retrieve the IPs from all servers in an active directory quickly.
Here is the answer:

#build a directorysearcher with ldap filter to get only computers
#if only a single server should be determined, change the * in name=* to name=<servername> (without <>)
$ds = new-object system.directoryservices.directorysearcher("(&(objectcategory=computer)(name=*))")

#get the computernames only
$computers = @($ds.findall() | % { ([adsi]$_.path).properties['name'] })

#loop through the names and try collect the IPs using wmi and list them
foreach($c in $computers)
  {
Get-WmiObject -computer $c -query "select * from win32_networkadapterconfiguration" | where-object { $_.ipaddress.count -gt 0 } | foreach-object { "$($c): $($_.ipaddress)" }
  }

Have fun.

(Update) SCCM vNext and Powershell

A few weeks ago,
(http://www.scapaot.de/blog/?p=57),
I have written about the question if there will be Powershell support in SCCM vNext.

On yesterday I had the chance to listen to a very interesting talk from Microsoft about the user centric software deployment and SCCM vNext.
There I had the chance to ask about the Powershell support in the next version.

The answer is:

The next version has support for the same WMI classes
as it has in SCCM 07.
And there will be new WMI classes for the new features.
Powershell support is there using WMI cmdlets.

And perhaps the SDK for vNext will have some little more infos about using the Powershell to manage SCCM.
Cmdlets are not planed at the moment.

So, for all of you want to learn how to automate SCCM,
go out and learn something about WMI.