PowerShell ver. SCCM 2007

SCCMWhen you want some information from SCCM 2007 using PowerShell you have two options: using ADO.NET to talk to SCCM DB directly (yeah, right… Uśmiech z językiem), or using WMI interface. If there are other ways to get there – I’m not aware of them (yet). Puszczam oczko

Working with good-old Get-WmiObject got better (IMO) in v3 – it’s unintentional (I’m guessing), but it’s the fact. Today I would like to share simple “trick” I use daily on my v3 admin workstation to get some info out of SCCM using WMI.

First of all – I’ve defined $WMIStatic variable:

$WMIStatic = @{            
    ComputerName = $Server            
    NameSpace = "root\sms\site_$Site"            
    ErrorAction = 'Stop'            
}

$Site and $Server point to server that you want to talk to. With that defined, you can get a lot info straight from SCCM WMI interface. E.g. list some classes available for you:

Get-WmiObject @WMIStatic -Class *Collection* -List

And now for the best part: v3 in action. It helps a lot with thing I do very often, listing collection that given workstation belongs to:

gwmi @WMIStatic SMS_R_System -Filter "Name = 'WAR000260'" |             
    % GetRelated SMS_Collection |            
    % Name

It’s obviously console-mode (aliases, positional parameters) but I usually just need a peek, so I do it interactively. And if I need to make sure that given workstation is a member of collection it suppose to be in I can do:

gwmi @WMIStatic SMS_R_System -Filter "Name = 'WAR000260'" |             
    % GetRelated SMS_Collection |            
    ? Name -Match PartOfCollectionName |            
    % Name

$WMIStatic is defined in my profile – so I have it available all the time. Makes working with SCCM so much easier at times.. Uśmiech And regarding ADO.NET and DB – did that too, but it’s not something I would recommend. ALTER/ DROP can cost you a lot there… Puszczam oczko

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s