Dela via


Configuration Manager PowerShell Tuesdays: Creating and Distributing a Package / Program:

I have long been a crusty old VBScript kind of guy, that just the way it is. I’ve been knocking out ‘short’ 300 line scripts for 10 plus years. In that time I have also gone through a few epic multi thousand line monstrosity scripts,,,, now that’s living. Many years ago at the Microsoft Management Summit (maybe 2008 or 2009) I was given a PowerShell book inside the attendee bag. Then and there I decided to take the leap from my precious wscript.exe to this new-fangled PowerShell thing…… It didn’t happen……. I fell back to the comforts of VBScript year after year. I am here to say now that I think I have crossed the threshold – PowerShell has found its way to the front of my scripting activities and has been paramount in the automation work that I have completed over the last twelve months.

With this blog post I hope to kick off an extended multi post look into some of the many PowerShell CMDLETS included with System Center 2012 Configuration Manager. In addition to examining the CMDLETS themselves, I will be punting in a few posts that should tie multiple pieces of Configuration Manager PowerShell automation into larger Runbook Automation solutions, so look out for those as well.

As reference, I have also completed two blog postings on running Configuration Manager PowerShell CMDLETS outside of a Configuration Manager console initiated PowerShell session, more specifically from System Center Orchestrator. These may be useful when approaching Configuration Manager automation.

In this particular posting, I will be taking a quick look at the following four CMDLETS

  • New-CMPackage
  • Set-CMPackage
  • New-CMProgram
  • Start-CMContentDistribution

There is not much to cover at any extreme depth with the execution of these four CMDLETS, they are fairly straight forward. Nevertheless this article will be a great kick off point and should set the rhythm for many more to follow.  

New-CMPackage:

This CMDLET quite simply creates a Configuration Manager Package. The Get-Help file for this CMDLET includes the following syntax.

New-CMPackage -Name <string> [-Description <string>] [-Manufacturer <string>] [-Language <string>] [-Version <string>] [-Path <string>] [-WhatIf] [-Confirm] [<CommonParameters>]

For my example I will be running

New-CMPackage –Name “7ZIP – PS Created” –Path “\\twocmsp1\c$\Packages\Software Distribution\7ZIP

As can be seen in the console, the results match the executed PowerShell cmd.

Ok Cool, but what about the other package configuration options such as distribution priority, I do not see a way to configure these using the New-CMPackage CMDLET? Correct, it does not appear all configurations of a package can be set when initially creating the package, however loping in the Set-CMPackage CMDLET extends the configuration capability.

Set-CMPackage:

This CMDLET configures an existing Configuration Manager Package. The Get Help file for this CMDLET includes the following syntax. I’ve trimmed this down to only one of the returned sets of syntax. There are three mostly identical, one each for Package ID, Package Name, and Package Input Object.

Set-CMPackage -Name <string> [-SecuredScopeNames <string>] [-NewName <string>] [-Version <string>] [-Manufacturer <string>] [-Language <string>] [-Description <string>] [-Path <string>] [-ForcedDisconnectDelay <int>] [-ForcedDisconnectEnabled <bool>] [-ForcedDisconnectNumberRetries <int>] [-MifFileName <string>] [-MifName <string>] [-MifPublisher <string>] [-MifVersion <string>] [-DistributionPriority <Priorities> {High | Normal | Low}] [-ShareName <string>] [-ShareType <ShareTypes> {ShareCommon | ShareSpecific}] [-WhatIf] [-Confirm] [<CommonParameters>]

For my example I will be running:

Set-CMPackage -Name "7ZIP - PS Created" -DistributionPriority High

Which results in the following changes made on the package:

New-CMProgram:

With a package created, we will need a Program. The Get-Help file for the New-CMProgram CMDLET includes the following syntax. This is for a standard program only, the help file also includes some syntax for a device program. Use Get-Help New-CMProgram to see all syntax.

New-CMProgram -PackageName <string> -StandardProgramName <string> -CommandLine <string> [-RunType <RunType> {Normal | Minimized | Maximized | Hidden}] [-ProgramRunType <ProgramRunType> {OnlyWhenUserIsLoggedOn | WhetherOrNotUserIsLoggedOn | OnlyWhenNoUserIsLoggedOn}] [-RunMode <RunModeType> {RunWithUserRights | RunWithAdministrativeRights}] [-UserInteraction <bool>] [-Reconnect <bool>] [-DriveMode <DriveModeType> {RenameWithUnc | RequiresDriveLetter | RequiresSpecificDriveLetter}] [-DiskSpaceUnit <DiskSpaceUnitType> {KB | MB | GB}] [-DriveLetter <string>] [-WorkingDirectory <string>] [-DiskSpaceRequirement <string>] [-Duration <int>] [-WhatIf] [-Confirm] [<CommonParameters>]

For my example I will be running:

New-CMProgram -PackageName "7ZIP - PS Created" -StandardProgramName "7ZIP - Program" -CommandLine "msiexec.exe /I 7z920.msi /quiet /norestart"

The results are much to be expected. 

Take note of the standard Environment settings when no options have been specified with the New-CMProgram CMDLET.

If desired, additional configuration can be made at creation time. For instance if adding the -ProgramRunType and -RunMode parameter when running the New-CMProgram CMDLET, such as

New-CMProgram -PackageName "7ZIP - PS Created" -StandardProgramName "7ZIP - Program: -CommandLine "msiexec.exe /I 7z920.msi /quiet /norestart" -ProgramRunType WhetherOrNotUserIsLoggedOn -RunMode RunWithAdministrativeRights"

The results are as follows:

Start-CMContentDistribution:

All right - we have a package and a program created. Next step is to distribute this bad boy to a single distribution point or distribution point group. No worries, we have an CMDLET for that. The Get-Help file for Stat-CMContentDistribution includes the following. NOTE: this is the output for only a standard package, there are unique commands for driver packages, operating system images, etc. however they are mostly similar to what is shown below. Run Get-Help Start-CMContentDistribution for a full listing.

Start-CMContentDistribution -DeploymentPackageName <string[]> [-CollectionName <string>] [-DistributionPointName <string>] [-DistributionPointGroupName <string>] [-WhatIf] [-Confirm] [<CommonParameters>]

For my example I will be executing

Start-CMContentDistribution -PackageName "7ZIP - PS Created" -DistributionPointGroupName TWOCMSP1

Once completed we can observe on the distribution point groups properties that the package has in deed been distributed.

Conclusion:

Very straight foreword stuff here. As seen, through a series of just a few Configuration Manager CMDLETS we can easily create a Package, Program, and distribute the package to a group of distribution points.

Comments

  • Anonymous
    May 22, 2013
    Great article. Has anyone else had trouble with the -SecuredScopeNames parameter for Set-CMPackage I'm trying to do Set-CMPackage -Id 'packageid' -SecuredScopeNames 'Scope Name' and getting a "No object corresponds to the specified parameters" error. It works with other parameters, just can't set the scope.

  • Anonymous
    May 22, 2013
    It seems that the -comment parameter for new-cmprogram behaves the same way.

  • Anonymous
    May 28, 2013
    Had anyone problems with the ShareName and ShareType Parameter ? set-cmpackage -id PAckageId -sharename Sharename -sharetype 2

  • Anonymous
    November 13, 2013
    How do you deploy this package in PS

  • Anonymous
    November 28, 2014
    I've had the same trouble with -SecuredScopeNames. This parameter does not seem to work.

  • Anonymous
    March 12, 2015
    Hi All

    For securityscope it can be set with below steps:

    [ARRAY]$SecurityScopeCategoryID = "RKR00002"
    [ARRAY]$PackageID = "RKR000FF"
    [ARRAY]$ObjectTypeID = 2 #SMS_Package ObjectTypeID
    Invoke-WmiMethod -Namespace "RootSMSSite_RKR" -Name AddMemberShips -Class SMS_SecuredCategoryMemberShip ` -ArgumentList
    $SecurityScopeCategoryID,$PackageID,$ObjectTypeID


    Refer: http://cm12sdk.net/?p=732

  • Anonymous
    July 24, 2015
    Here a script that resum all that http://windowscapture.blogspot.fr/2015/07/heres-script-powershell-to-duplicate.html