Montreal PowerShell User Group #01 - Material and pictures from my talk on Introduction to PowerShell

Here is the material from my presentation on Introduction to PowerShell at the first Montreal PowerShell User Group meeting that occurred yesterday (2015/09/15).

The Powerpoint presentation and PowerShell code is available on the meetup group page and Github:

Even thought I was a bit stress to present, I really loved the experience and I can't wait for the next meeting! We had a great group (17 people) who showed great interest and asked tons of questions!!

The next meeting will probably occur around the end of October.


PowerShell/SCCM - Create a Dynamic Variable list during the task sequence

In my previous article I talked about SCCM Application and how to retrieve the applications targeted to a user.

Today I'll show how we can build a function to create a list of dynamic variables. This would be used in a Task Sequence during the Operating System Deployment in the task "Install Application".

First we will need to find the list of applications and then create a variable with a specific pattern for each of them.

What does it look like inside the task Sequence ?

Before we dig into the PowerShell, I think it is important to understand where everything will goes.

In the following task "Run PowerShell Shell Script", the script will retrieve in SCCM all the Applications advertised on the users (showed in previous article) and then create a bunch of variables that will be used in the task "Install Application".


PowerShell/SCCM - Find Applications advertised to a user

The following function helps you retrieve all the deployment that a user is supposed to received.

We use this during the Operating System Deployment (OSD). Using the UDI we get the user account that will receive the workstation currently being deployed. This script allow us to retrieve in SCCM all the Application advertised on the user that needed to be deployed on the computer during the task sequence.

I know this could probably be done with the Configuration Manager module, but I'm pretty new with it and I was not sure it could be loaded in a task sequence, if you have the answer let me know in the comment section.

Here is the step by step how I found my solution. You can also go straight to the function at the end of this article.

Define Default Parameters

First I define a splatting to avoid repeating the same parameters in each command.
# Define default parameters (Splatting)
$Splatting = @{
    ComputerName = "Sccm01.lazywinadmin.com"
    NameSpace = "root\SMS\Site_FX1"

Retrieve a user in SCCM CMDB

Then I need to find a user in the SCCM Database to retrieve its ResourceID.
# Find the User in SCCM CMDB
$User = Get-WMIObject @Splatting -Query "Select * From SMS_R_User WHERE UserName='FxTest'"

Retrieve the collections the user is member of

# Find the collections where the user is member of
$Collections = Get-WmiObject -Class sms_fullcollectionmembership @splatting -Filter "ResourceID = '$($user.resourceid)'"