/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Upgrading MSH, My first Windows PowerShell Commands "," Some more Windows PowerShell Links and info. "," Windows PowerShell (Monad / MSH) "," Simple port scanning using Monad "," Large AD queries in Monad "," Sharepoint provider for Monad "," access ADSI WinNT provider from Monad Part 2 "," MSH Community Workspace, TFSC provider and videos "," more Monad scripts, and a bit more CSV "," working with CSV files in MSH (part two) "," ")

Wednesday, April 26, 2006

 


PowerShell and SMS 2003



Yesterday I did read about this MMS session from Jim Bradbury:
LC09 – Automating SMS Tasks with Monad Scripting, here :Day 1 - MMS 2006 - Part 2

Nice to hear he did mention my blog, I did see this session on the agenda of the MMS and did already think it did look interesting, as I just did an SMS 2003 implementation and still I'm busy with it, and I also Used Monad (and still do use PowerShell) a lot with SMS.

So I hope there will be a transcript of this session.

but then I did realize that I only have one SMS example yet on my blog and it's hidden in the CSV series. (it's in part 1),
I made this into a 36 lines select statement (one-liner ;-) to do a Crosstab software report building from the CSV sample using a lot of SMS queries AD and CMDB info that way in PowerShell.
the rest I mostly did prototyping in MSH, but to make it up a bit I post some basic examples here :

basicly I used 3 methods to use SMS with PowerShell,

1) WMI queries like the one in the CSV example.

2) Using the Client COM Objects :

getting available actions (as in controlPanel)

MowPS>$mgr = new -com CPApplet.cpappletmgr
MowPS>$mgr.GetClientActions()

ActionID                      Name                                       DisplayNameResID DisplayNameResDLL
--------                      ----                                       ---------------- -----------------
{00000000-0000-0000-0000-0... MSI Product Source Update ...                         10010 cfg_res.dll
{00000000-0000-0000-0000-0... Hardware Inventory Collect...                         10001 cfg_res.dll
{00000000-0000-0000-0000-0... Discovery Data Collection ...                         10004 cfg_res.dll
{3A88A2F3-0C39-45fa-8959-8... Request & Evaluate User Po...                         10007 cfg_res.dll
{8EF4D77C-8A23-45c8-BEC3-6... Request & Evaluate Machine...                         10008 cfg_res.dll 


and start them :

# Performing a Computer and User Policy Evaluation

$mgr.GetClientActions() |? {$_.name -like 're*'} |% {$_.PerformAction()} 

# You can also use the Object directly, without putting it into a variable first :

# Trigger a Hardware Invertory

(new-object -com CPApplet.cpappletmgr).GetClientActions() |? {$_.name -like 'hardware*'} |% {$_.PerformAction()} 


The triggering of the computer policy is very handy after sending software to the client, as this has to be done remote on the client, in the end I used a Vbscript and PSExec, as I don't have PowerShell deployed yet ;-)
But I did a lot of prototyping in MSH (PS).

3) you can Find a .NET DLL in the SMS SDK you can use to manage SMS :


# Make Managed Connection

[System.Reflection.Assembly]::LoadFile('c:\sms\Microsoft.SystemsManagementServer.Automation.dll')
$cred = get-credential
$sms = new Microsoft.SystemsManagementServer.Automation.smsprovider("Mowsms001",$cred.username,($cred.GetNetworkCredential().password),"Site_M03")

# list all defined queries

$sms.Queries.get('Y030003A') | fl QueryID,Name,SQLExpression 

# Add some direct rules

$Col = $sms.COLLECTIONS.Get('M03000AE')
$rule = new-object Microsoft.SystemsManagementServer.Automation.SMSCollectionRuleDirect("SMS_R_System",69438,"MowPC44")
$col.CollectionRules.add($rule)
$rule = new-object Microsoft.SystemsManagementServer.Automation.SMSCollectionRuleDirect("SMS_R_System",63535,"MowPC23")
$col.CollectionRules.add($rule)
$col.save() 


You can see, that I can just load the DLL into PowerShell and start using it.
This where just some basic examples, but I hope that this, together with the CSV power of PowerShell (see the CSV series) and working with SMS
I'm sure Jim Bradbury did a better job at this, but I wanted to do a post for the ones that,as me, could not be there and have to hope for a transcript

also you have to watch for big WMI queries in SMS that will take a long time and a lot of memory. (but most SMS admins I think will be used to that)
but in MSH it could stall the pipeline and also stop Ctrl-C from working (ctrl-Break will work but quits the Shell)

See this example :

$oq = new system.management.objectquery
$oq.QueryString = "select * from SMS_CM_RES_COLL_MOW000B6"
$mos = new-object system.management.ManagementObjectSearcher($oq)
$mos.scope.path = "\\SMSServer\root\sms\Site_MOW"

# Streaming (items one-by-one)

$mos.get()

# gathering / blocking (Items all at the same time)

$mos.get() | select name,ResourceID
$mos.get() | ft



b.t.w. this is only a collection, hence is still workable, the real
problems begin when I do this with big software queries.

the workaround is this :

MSH>1 | foreach { $mos.Get() } | select name,ResourceID

See also this
:NewsGroup thread (end of the thread)

I could only do a quick post a few examples, as I also was planning an item about some new features in PowerShell As Ref variables and switch-parameters to functions.
but still hope this is useful.

Dont't forget to use Get-Member on the SMS Objects to See whet they can do this helps a lot.

I will do this in an example to get the AD subnet and sitename of an IP adress or a Hostname, I hope to post later this evening .

Greetings /\/\o\/\/

Tags :


Comments:
Anonymous Anonymous
This comment has been removed by a blog administrator.
 
Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?