This simple powershell script will create a package in SCCM2012 with a single standard program, and distribute it to your DP Group. It uses the ConfigMgr native commands, and you can add/remove/change the parameters to customise the script for your own environment.
It does not create a deployment, but that’s easy enough to do, just add code like the following after the content distribution part:
Write-Host 'Deploying Application to Collection' $Deployment = Start-CMPackageDeployment ` -CollectionName MyCollection ` -PackageName $Pkg ` -StandardProgramName $Pkg ` -DeployPurpose Required
Create Package
<# ------------- CreatePackage v1 ------------- This script creates and distributes an SCCM2012 package with a single standard program Tested on: SCCM2012R2 //Instructions// Set the variables below as required #> ############### ## Variables ## ############### # ConfigMgr Site Code $SiteCode = "ABC" # Name of the package $Pkg = "7zip" # Location of Source files $Source = "\\MySCCMServer\PackageSource\7Zip" # Installation command line $CommandLine = "setup.exe -s" # Required amount of disk space $DiskSpace = "200" # Units for Disk space requirement, eg KB, MB or GB $DiskUnit = "MB" # Maximum allowed run time $Duration = "16" # Program can run, eg "WhetherOrNotUserIsLoggedOn", "OnlyWhenNoUserIsLoggedOn", "OnlyWhenUserIsLoggedOn" $RunType = "WhetherOrNotUserIsLoggedOn" # Run mode, eg "RunWithAdministrativeRights" or "RunWithUserRights" $RunMode = "RunWithAdministrativeRights" # Allow user to interact? $UserInteraction = $False # Allow program to be installed from task sequence? $EnableTS = $True # Distribution Point Group to distribute content to $DPG = "All Distribution Points" # Import ConfigMgr Module Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' $Drive = $SiteCode + ':' cd $Drive cls $ErrorActionPreference = "Inquire" ## Create the Package ## write-host 'Creating Package' $Package = New-CMPackage -Name $Pkg -Path $Source ## Create a Program write-host 'Adding Program' $Program = New-CMProgram ` -PackageName $Pkg ` -StandardProgramName $Pkg ` -CommandLine $CommandLine ` -DiskSpaceRequirement $DiskSpace ` -DiskSpaceUnit $DiskUnit ` -Duration $Duration ` -ProgramRunType $RunType ` -RunMode $RunMode ` -UserInteraction $UserInteraction ## Update Program write-host 'Updating Program' $ProgramUpdate = Set-CMProgram ` -Name $Pkg ` -StandardProgramName $Pkg ` -EnableTaskSequence $EnableTS ## Distribute Content to DPs ## write-host 'Distributing Content to DPs' Start-CMContentDistribution -PackageName $Pkg -DistributionPointGroupName $DPG write-host 'Done!' -ForegroundColor Yellow
Hello
Thank you for the info. It still works. 🙂
At the “## Update Program” section, I have received an error with version CB 2111.
The error was something like:
cmdlet Set-CMProgram at command pipeline position 1
Supply values for the following parameters:
StandardProgram:
I have added at the end of command “-StandardProgram” without any value and it worked.
Set-CMProgram -Name $Pkg -StandardProgramName $Pkg -StandardProgram -EnableTaskSequence $EnableTS
Regards.