Jump to content


ConfigMgr 2012 Automation with Powershell

Recommended Posts



I found the script below on an old TechNet forum post. I'm curious about the variables being used. Are they ConfigMgr variables or something the poster created? If they are known variables in ConfigMgr where can I find these values? Is there a documented list somewhere?

Start-CMSoftwareUpdateDeployment -CollectionName $CollectionName -DeploymentType $DeploymentIntent -DeploymentName $DeployMentName -DeploymentAvailableDay(Get-date) -DeploymentExpireTime (Get-Date)



Share this post

Link to post
Share on other sites

Exactly like Peter said, they've been manually defined by the creator. Here's an example of how it could look like:

$CollectionName = "Test Collection"
$DeplymentIntent = "Install"
$DeploymentName = "Test Deployment"
Start-CMSoftwareUpdateDeployment -CollectionName $CollectionName -DeploymentType $DeploymentIntent -DeploymentName $DeployMentName -DeploymentAvailableDay(Get-date) -DeploymentExpireTime (Get-Date)

Bare in mind though, this is a really basic way of writing a PowerShell script.

Share this post

Link to post
Share on other sites

Here's a great book (I haven't read it myself though):




Also have a look at Kaida's excellent PowerShell example resources:



  • Like 1

Share this post

Link to post
Share on other sites

So I've recently had some challenges at work having to setup multiple deployments to multiple collections at various times. Bit of a pain in the butt and very tedious and repetitive. Today I had a lovely day off work to myself, low and behold I therefore ended up writing a script to automate my patching process. By no means am I a scripter of any sort, in fact I'm a beginner but with some time, testing and googling I have come up with the below which I think is pretty generic enough for anyone to modify


It will read a CSV, create collections based on what I call "Phase" and add a prefix so all my collections come out as "Server Patch Management - XXXXX", it will then insert the hostnames into the newly created collections, and finally deploy your chosen SUP to all the collection based on the time and date specified in the CSV.


Its pretty simple:


1 - You create a CSV file as described in the script, keeping to that EXACT same format with those exact same headers. By the way the UK column is actually time, we run in various time zones so I used a column header called UK


2 - Set your software update group that you want to deploy. In this case I want to deploy a SUG called "Microsoft - Oct 2015 - Windows 7 Security Patches"


3 - Add a naming prefix (not required but I prefer to add a naming prefix to my collection so they can be clearly identified). That's all, away you go


4 - Don't forget to change ABC for your sitecode and change the path to the location of where your module is located



On the surface it looks tricky to decipher but try it out first, once it starts making sense you can tinker with the parameters and customise for your own organisation.


Open to suggestion on how I can improve this as well.



Use a imported CSV containing Phase, Date, Time and Computer name to create a software update deployment.

format of the CSV must be as follows:


Pilot 1,10/09/2015,10:00,UKW00000

Pilot 2,14/09/2015,10:00,UKW11111

Wave 1A,08/10/2015,15:30,UKW22222

Wave 1B,09/10/2015,06:00,UKW33333

Wave 1B,09/10/2015,06:00,UKW44444

Wave 1B,09/10/2015,06:00,UKW55555

Wave 1C,09/10/2015,11:00,UKW66666

Addition columns in the CSV will be ignored



#Set Module Location

import-module C:\windows\ConfigMgrConsole\bin\ConfigurationManager.psd1

cd ABC:


# Set Input File, Enter Name Of Software Update Group & Set Prefix Name For Collections

$inputfile = Import-CSV 'c:\users\username\desktop\input.csv'

$updategroup = "Microsoft - Oct 2015 - Windows 7 Security Patches"

$collectionprefix = "Server Patch Management - "

# This Will Set 3 Differing Input Variables Which Are Used Later

$input1 = $inputfile | select phase | sort phase -Unique

$input2 = $inputfile | select hostname,phase

$input3 = $inputfile | select phase,date,uk | sort phase,date,uk -Unique

# Create A Loop From Input1

# Read Input1 & Create New Device Collections Based On Values In The "Phase" Column Adding A Prefix of "Server Patch Management - " To Each

ForEach ( $entry in $input1 ) {

$collection = $collectionprefix+$entry.Phase

New-CMDeviceCollection -Name $collection -LimitToCollectionName "All Systems" -ErrorAction SilentlyContinue


# Create A Loop From Input2

# Read Input2 & Add Computers Found Under The "Hostname" Column Into The Collections Created Above.

ForEach ( $entry2 in $input2 ) {

$collection2 = $collectionprefix+$entry2.Phase

Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collection2 -ResourceId $(get-cmdevice -Name $entry2.hostname).ResourceID


# Create A Loop From Input3

# Read Input3 & Obtain Target Collection, Create Deployment Name, Invert Date & Deploy Update Group

ForEach ( $entry3 in $input3 ) {

# Set Collection Prefix

$collection3 = $collectionprefix+$entry3.Phase

# Concatenate Group & Collection To Create Deployment Name

$deploymentname = $updategroup + " - " + $collection3

# Invert DD/MM/YYYY Date Format Into YYYY/MM/DDD Which Is Correct SCCM Syntax

$availday = $entry3.Date.split("/")[0]

$availmonth = $entry3.Date.split("/")[1]

$availyear = $entry3.Date.split("/")[2]

$availyyyymmdd = $availyear + "/" + $availmonth + "/" + $availday

Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName $updategroup -CollectionName $collection3 -DeploymentName $deploymentname -DeploymentType Required -TimeBasedOn UTC -DeploymentAvailableDay $availyyyymmdd -DeploymentAvailableTime $entry3.uk -DeploymentExpireDay $availyyyymmdd -DeploymentExpireTime $entry3.uk -UserNotification DisplayAll


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...