PowerShell and Configuration Manager 2012 R2–Part 3

Doctor Scripto

Summary: Use the Configuration Manager cmdlets to update applications in distribution points.

Hey, Scripting Guy! Question Hey, Scripting Guy!

I’m forever having the nightmare of going clickity, click, click, click when I’m working with my distribution points—especially when updating applications and packages. There must be some way to do this in Windows PowerShell. Can you help me?

—DS

Hey, Scripting Guy! Answer Hello DS,

Honorary Scripting Guy, Sean Kearney, is here, shedding more light on the Configuration Manager cmdlets!

 Note  This is a five-part series that includes the following posts:

I feel your pain. Whenever I have to develop and test packages for a client, invariably, it’s the same process over and over: create the package or application, update the distribution point, make a change, click away again…

Anybody at all who’s done this knows it’s another good way to burn in the buttons on your brand new mouse. This is great if you like a new computer mouse every week and don’t mind the odd case of carpel tunnel.

Me? I prefer my hands to remain useful and keeping the company mouse replacement budget well under control. I’d rather that money went towards a new Surface Book for me.

Getting the list of these available cmdlets is the same as accessing a list of collection cmdlets. Simply run Get-Command and filter away!

Get-Command –module ConfigurationManager *Distribution*

Image of command output

As you can see, the list here is a little more refined that the one for collections. Outside in the Land of PowerShell, we can now do some of those tasks as a single line or small script instead.

One of the tasks I was forever doing (especially when debugging packages or applications) was updating the distribution points. That’s now simply a cmdlet!

If I’d like to update the application called ‘HSG App’ with a particular program called ‘HSG MSI Deployment’, instead of clicking madly through the console, I can do this:

Update-CMDistributionPoint –ApplicationName ‘HSG App’ –DeploymentTypeName ‘HSG MSI Deployment’

At this point, it’s happily running in the background.

But where did I pull those names from? I used two additional cmdlets to get the application display name and the display name for the application type.

First we can run the Get-CMApplication cmdlet, which will give us an object that contains every application we have access to in the console.

Get-CMApplication

To filter this list to what we’re looking for, we can target the Name or PackageID. In the following example, we’re using the display name of the application called ‘7 zip’.

Get-CMApplication –Name ‘7 zip*’

This will produce a list of all entries in the application model that match the name ‘7 zip*’ at the beginning. You can also target by the PackageID if you pipe the results to a Where-Object filter.

Get-CMApplication | Where { $_.PackageID –eq ‘SMS00123’ }

When you have your application in question, you’ll need to obtain its name, which is stored under ‘LocalizedDisplayName’, and then place that into an object.

$AppName=(Get-CMApplication | Where { $_.PackageID –eq ‘SMS00123’ }).LocalizedDisplayName

With this information, we now need to find the deployment types that are made available by the application. For this, we use the Get-CMDeploymentType cmdlet.

We supply it the application name that we captured previously, and we can filter on the names of the deployment types.

Get-CmDeployment –ApplicationName $Appname

If there is more than one, you can pipe it through Where-Object to clean up the list. In the following example, we’re only targeting those with the word ‘MSI’ in the deployment type’s DisplayName:

Get-CmDeployment –ApplicationName $Appname | Where { $_.LocalizedDisplayName –match ‘msi’ }

When we have it, we’ll also store that away in an object. We’ll call this one (strangely enough) $DeploymentType.

$DeploymentType=Get-CmDeployment –ApplicationName $Appname | Where { $_.LocalizedDisplayName –match ‘msi’ }

With this provided environmental data, we would update our distribution point as previously, except we supply the PowerShell variables.

Update-CMDistributionPoint –ApplicationName $Appname –DeploymentTypeName $DeploymentType

There is so much more we can do with these cmdlets, such as establishing new distribution points, or even modifying memberships of deployment groups. I could easily write for a week about this alone!

DS, now you know how to update distribution points with the PowerShell cmdlets in Configuration Manager. Tomorrow we’ll actually use the cmdlets to work with packages. See you soon!

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.

Sean Kearney, Honorary Scripting Guy and Cloud and Datacenter Management MVP 

0 comments

Discussion is closed.

Feedback usabilla icon