You are browsing the archive for Powershell.

Avatar of timdk

by timdk

ConfigMgr Cmdlet Library v5.0.8328.1155 released

2:05 pm in Configuration Manager by timdk

metro-powershell-logoA quick blog post to inform you that Microsoft yesterday released version 5.0.8328.1155 of the System Center Configuration Manager Cmdlet Library.

This version includes support for Configuration Manager 1511.

Full list of versions of Configuration Manager supported in this release:

    • System Center 2012 Configuration Manager SP2
    • System Center 2012 R2 Configuration Manager
    • System Center 2012 R2 Configuration Manager SP1
    • System Center Configuration Manager (current branch version 1511)

    Full details and download link can be found here.

Avatar of timdk

by timdk

Creating a Software Update Group based on an input file

3:29 pm in Configuration Manager by timdk

Depending on your patching process the way you structure and create Software Update Groups in Configuration Manager 2012 may vary. At quite a few customers I see a scenario where the monthly patch review board spawns a spreadsheet with the Updates to be released into the environment. Having to create a Software Update Group based on that spreadsheet manually can be a time consuming task for the Configuration Manager administrator.

With the new powershell cmdlets available in Configuration Manager 2012 Service Pack 1 I found out it was really straightforward to automate the creation of the Software Update Groups and populating them based on a csv input file. For someone like me, having very little experience with Powershell and scripting in general, it only took a few hours of playing in my lab to accomplish this. Lets have a look at the steps I’ve walked through.

Step 1 – The input file

 

20130520-SUGwithPowershell_01

Example of a .csv input file.

As a source for input we will use a csv file. As you will see later on, this type of file is very easy to use with powershell. If you need to start from an Excel (.xls, .xlsx) file you can easily save it in csv format.

The input file usually contains a lot of information on the updates to be deployed. The most common ones are the Article ID, Bulletin ID and the description of the update itself. I decided to use the description field as it is most likely a unique field. Fields like the Article ID and Bulletin ID can be applicable for multiple updates (eg for different updates per CPU architecture).The screenshot shows an input file from my lab.

Final part of this step is to copy the file on a dedicated folder on the site server.

Step 2 – Building the script

 

To automate the import we will be using 3 powershell cmdlets: Import-csv, Get-CMSoftwareUpdate and New-CMSoftwareUpdateGroup. Below is a short summary on what the cmdlets can be used for:

  • The Import-Csv cmdlet creates table-like custom objects from the items in CSV files. Each column in the CSV file becomes a property of the custom object and the items in rows become the property values. Click here for more details: http://technet.microsoft.com/en-us/library/hh849891.aspx
  • The Get-CMSoftwareUpdate cmdlet retrieves configuration settings for one or more software updates. More details on the cmdlet can be found here: http://technet.microsoft.com/en-us/library/jj850180.aspx
  • The New-CMSoftwareUpdateGroup cmdlet creates a software update group for Microsoft System Center 2012 Configuration Manager. More details can be found here: http://technet.microsoft.com/en-us/library/jj821751.aspx

The Import-csv cmdlet will be used to read the information from the input file. Based on the Displayname of an update we will use the Get-CMSoftwareUpdate cmdlet to determine the CI_ID that each update has in Configuration Manager. We will need the CI_ID’s as input for the New-CMSoftwareUpdateGroup cmdlet to populate the newly created Software Update Group.

There are two pieces of information we will need as input for the script: the path and name of the input file and the name of the new Software Update Group to be created. We should be able to provide these as parameters for the script and prompt for them in case the administrator forgets to specify them.

Putting all these elements together results in the script shown in the screenshot below:

20130520-SUGwithPowershell_02

The CreateCMSUG.ps1 script.

Save the script in the dedicated folder on the site server where the input file was saved previously.

Step 3 – Connecting via Powershell and running the script

 

20130520-SUGwithPowershell_03

Connecting to Powershell via the Console.

Connecting to the Configuration Manager site with powershell can be done via the console. Click the blue tab in the top left corner and select Connect via Windows Powershell. A new window will open and the prompt should look like PS %Sitecode%:\>

When running the script you can provide the required parameters immediately: the first one is the name and location of the input file and the second one is the name of the new Software Update Group. In case you do not provide them you are prompted.Notice that upon succesful creation of the Software Update Group the details of that SUG are shown. The LocalizedDisplayName property shows the name that was provided as input parameter for the script.

Step 4 – The result

 

20130520-SUGwithPowershell_06

The newly created Software Update Group

Open the Configuration Manager console and go to the Software Library workspace, then click Software Update Groups. Your newly created Software Update Group should be listed. If

it is not make sure to refresh the view. Optionally you can change the name of the Software Update Group by modifying its properties.

 

 

 

20130520-SUGwithPowershell_05

Current members of the Software Update Group

To check the membership you can either double-click the Software Update Group or right-click and select show members.

Conclusion: given the fact that I am not a scripting expert, there is probably much room for improvement on the script. As I am eager to learn more on Powershell with ConfigMgr I will further work on optimizing the script in the future. For now I have a quick and easy solution to create my Software Update Groups and save a lot of time.

The script can be downloaded here:CreateCMSUG Powershell script (1874)

Hope it helps!

Tim