SCCM: Code breakdown – Deploy Application to Device Collection

As you might have noticed, I’m having fun playing around with SCCM lately and have really noticed that PowerShell is king here.

While the application has great potential, I personally feel that the GUI is lacking functionality which you can only obtain through PowerShell.
Of course this isn’t a problem, merely a challenge in some cases, but I feel that they could’ve stepped up a bit.
It at least explains why I see so many SCCM admins playing around with PowerShell.

For today I thought I’d break down my code and reasoning behind it a bit more, so in case you’re just here for the code, scroll down 🙂

The problem

Well, it’s not really a problem, but more of a speed related issue that I’ve decided to make this script:
If you have created an application, you want to deploy this to a collection because well… that’s simply how it’s used 🙂

Now the problem with the GUI for me was that I can’t deploy multiple applications to multiple collections at the same time because… I have no reason why not!

The solution

I’m sure it’s not the most elegant solution and I still have some fine tuning to do, but so far Out-GridView is my poison of choice 🙂

Let’s start

We start off with the default start of an Advanced Function or Script

[CmdletBinding()] allows us to transform our Script/Function to an Advanced version, giving it access to Common Parameters such as -Verbose -WhatIf and more.
I’ve also described this in a previous post, so in case you want some more theory on how/what/why there, please be sure to read up there.

Now I need to make sure that I actually get a parameter value included by the user and if you want you can manually specify the Device Collection to which you want to Deploy applications. For this I use the [ValidateNotNullOrEmpty()] Validation Attribute, which does exactly what it says.

Last but not least, while you CAN enter your own Device Collection name, I have provided a built-in solution using Out-GridView , that allows you to select one or multiple Device Collections, which it automatically looks up for you.

The best part here is the -PassThru parameter, which takes the information selected and passes it through to whatever you want to do with it next!

Now we begin {}

As expected, we’re now starting the begin statement to define some default information we can use throughout the script and report some information back.

Here I’m simply getting the available Distribution Group [I simply have 1 DG with 4 nodes, so in case you have multiple, you might want to hardcode that one for now, as I’ve not made this compatible with multiple] and the available Applications and writing them to variables.

I’m also writing some Verbose output, which can come in handy when troubleshooting the script.
I have picked up this habit by looking at a lot of code from Jeffery Hicks.

One of the handy tips that I’d recommend using is the following bit

2 Bits to use here:

  1. In case you want to refer to a Property of a Variable, without having to store it in its own variable, you can use $
    However, if you want to refer to this within your script, it won’t work “out of the box” or it won’t display the expected value.
    You will need to use sub-expressions, as explained by Stefan Stranger here.
  2. $MyInvocation.MyCommand displays the currently executed command.
    The MyInvocation variable is one of the selection of Automatic variables, which will always be available to you.
    $MyInvocation has various interesting values which you can use when troubleshooting remotely, so I would advise playing around with it 🙂

On to the Process {}

Once you get used to the coding, things aren’t all that difficult, so while the bulk of the code resides in the process {} block, it’s not even too hard to read/comprehend:

Here I simply get a list of all the applications available, so I can simple select whichever one I need to deploy [using Ctrl + click or Shift + click you can select multiple Applications, just as with the Device Collections].

Now for each of the applications selected, I will distribute the content so it’s available, and then deploy the application to the selected Device Collection(s).

Last but not least, once I’ve deployed the application, I will enforce that the Device Collection will need to request their machine policy ASAP.

As mentioned before, this bit of code isn’t difficult or complex, you just need to know which cmdlet does what and you’re golden.

Known issues

As mentioned before, there still needs to be some polishing done to clean everything up, but as far as I am aware, these are the 2 known “issues”:

  • The script currently takes into account 1 single Distribution Group.
    If you have more than 1, either make your own adaptation to the script, or hard code the required Distribution Group.
  • Currently on Content distribution, you will receive an “error” message if the application has already been deployed.
    Luckily the error message tells you that this is the case, but it’s still red text that I’d prefer to have replaced in a later version of the script in order to make it more userfriendly.

Final Code

In case you didn’t care for all the explanation above, come get the script here 🙂
In case you’ve read all of the above, I hope it helped you a bit!


Happy Scripting! 🙂


#OSC – Journey into PowerShell – SlideDeck and code

Hi all,

It’s been a while, but I’ve kept myself busy in the meantime.
During my last post on my blog, I was waiting for an assignment at my new job at OSC, only to be presented with a new challenge which kept me from posting for a while [expect more posts soon!!].

In the meantime I had also agreed to provide small training/demo session on PowerShell along with my new colleague Danny den Braver, to show people how awesome it actually is, while even showing them some PowerShell on Linux things [a few Linux guys there 🙂 ].

As promised at the end of the demo, here’s all the code as used by us that day:

OSC – A journey into PowerShell


Happy scripting 🙂


Knowledge is power..

I’ve recently had some discussions with my colleagues about certifications, experience, knowledge etc. and was asked to share information on how I got to where I am today and what I use to keep furthering up.

While I had given those colleagues a direct answer and had thought about writing an email to several of them with some basic information, I thought sharing this information with a larger audience would be handy…. That way I can simply update the information and point to my site if there’s a change.

So without further ado..

While always being keen on learning, I was particularly triggered by 2 quotes made by Don Jones [Pluralsight and PowerShell guru] which I think are essential mindsets that should help you progress:

If you’re not willing to invest in your career, why should anyone else?


Your career is your career, not your company’s. You should be focusing on the technologies and techniques that you know are important to the industry, whether your company needs you to, wants you to, or pays for you to or not

I could easily copy more quotes from him that I find interesting, but instead I’ll just refer to 2 posts made on his site which I would highly recommend reading:


Less talk, more do..

Besides just theory and articles, here are some resources which I recommend using when trying to further your career [focused on Microsoft curriculum].
Also know that furthering your career means certifications, theory and experience… so don’t just focus on one and not the other.


  • Microsoft Virtual Academy
    Microsoft’s counterpart to Pluralsight, only this one is free, but restricted to purely Microsoft products
  • Microsoft TechNet Virtual Labs
    In case you need some hands-on access to a lab for a specific subject.
  • Microsoft Channel 9
    More access to video training, seminars and other activities such as Build, Summits etc.
  • Pluralsight
    Awesome access to video training.
    Not free [except for trial period], but personally I think worth every penny.
  • Microsoft Press Store
    Official Microsoft books which can be handy for your certifications.
    Be aware on the lookout for offers which can easily provide up to 40% discount.
  • Manning
    Awesome technical books to expand your knowledge.
    While these don’t usually focus on certifications, they tend to have a lot of actual real-world subjects.
    Not to mention their MEAP [Manning Early Access Program], which allows for access to books while they are still being written and the fact that buying a physical book automatically gives you access to the e-book version [why don’t other publishers do this…].
  • Test exams for Microsoft can be done through either of the following companies:
    Measure-Up , Transcender of Kaplan Selftest.

Personal experience

Try and find user groups relating your field of interest near to you.
Networking can really help you get in touch with like minded people and this will further your chain of knowledge at lightning speeds].
For The Netherlands here are some resources to known User Groups [UG’s]:

  • DuPSUG
    Dutch PowerShell User Group
  • WMUG
    Windows Management User Group in The Netherlands [also SCCM UG]
    NL VMWare User Group

Besides User Groups, you also have Facebook Groups and of course Twitter feeds.
On my New to PowerShell post you can find some PowerShell related Twitter feeds that might be interesting.


All in all

Be willing to spend time to grow..
While I’m sure some people will tell me I’ll never grow any further, I’m sure they meant my physical stature… right @365Dude? 😉

Don’t let others keep you down, but it takes effort even stay afloat in IT.
If you’re the lazy type or don’t like learning, learn efficiently.

If that still doesn’t do it for you, IT might not be the branch for you.
In which case, don’t be surprised if you get automated in the near future 🙂