PowerShell and Configuration Manager 2012 R2–Part 5
Summary: Use the Configuration Manager cmdlets to create an application.
Oh, Scripting Guy! I want to get home at a decent hour today, but I need to bring this massive list of applications into Configuration Manager. I heard the Configuration Manager cmdlets can do this, but I need some help. So…er…*Cough*…HELP!
Honorary Scripting Guy, Sean Kearney, is here today to help you. I know vividly what you’re talking about. I’ve had to do the same thing.
Note This is a five-part series that includes the following posts:
- PowerShell and Configuration Manager 2012 R2–Part 1Load the Configuration Manager cmdlets and make a basic site connection.
- PowerShell and Configuration Manager 2012 R2–Part 2Use the Configuration Manager cmdlets to work with site collections.
- PowerShell and Configuration Manager 2012 R2–Part 3Use the Configuration Manager cmdlets to update applications in distribution points.
- PowerShell and Configuration Manager 2012 R2–Part 4Use the Configuration Manager cmdlets to work with driver packages.
- PowerShell and Configuration Manager 2012 R2–Part 5Use the Configuration Manager cmdlets to create an application.
Configuration Manager is a great environment for package and application deployment and for managing the enterprise. The trick is getting the information in there for deployment.
So first, let’s see the pile of cmdlets you have to work with:
Get-Command –module configurationmanager *Application*
This list is quite impressive. There appears to be almost nothing we can’t do with applications. If you look at yesterday’s post, there is an equally strong pile for creating software packages.
After looking at this pile, my thought is, “Why would anyone repeatedly use the GUI?”
Let’s script it all!
The first part I think is pretty cool is easily getting a list of all applications or software packages in Configuration Manager in one line. We can use this to show all the applications that are available:
Get-CmApplication | Select-Object LocalizedDisplayName
Or to see all of the available packages, use:
Get-CmApplication | Select-Object Name
To create a new software package requires two cmdlets, New-CmPackage and New-CmProgram.
New-CmPackage creates the base package. Much like the GUI, there is a lot of information you can provide, but only certain bits are actually required.
If you want to create a basic package with the source files on a server file share that targets a user (pretty typical), you’d execute New-CmPackage in this fashion:
$PackageName=’HSG Cool Program’
$PackageDescription=’Some amazing App written by the PowerShell Community’
$CMPackage=New-CmPackage –Name $Packagename –Description $PackageDescription –Manufacturer $Manufacturer –Language $Language –Version $Version –Path $SourcePath
We grab the output so we can get the PackageID for our next step, which is to add a program to our package containing source files.
If you were to type $CMPackage.PackageID, you’d see a familiar piece of information on your screen! The very ID we normally see in the Configuration Manager console.
We can now run New-CmProgram and create a launch for this application. We’ll presume the application that launches it is called setup.exe, and we’ll give it an appropriate name:
$CMProgram=New-CMProgram –Commandline $ProgramCommand –PackageID $CMPackage.PackageID –StandardProgramName $ProgramName –DiskSpaceRequirements $DiskSpace –Diskspaceunit $DiskSpaceUnit –RunType $RunType –RunMode $RunMode
With Configuration Manager 2012, if you prefer to see the packages show up in the software center on the client, you need to clear the Suppress program notifications option. You could go to the GUI for this, but we can add the Set-CmProgram cmdlet to the script in question. We supply the package ID and the name of the program as the key parameters:
Set-CmProgram –PackageID $CMPackage.PackageID –ProgramName $CmProgram.ProgramName
Applications are not that much different. There are two cmdlets to work with. The biggest difference with applications is that you need to add your detection type to confirm the installation.
The first part is to create the entry in the application list for our custom app. Most of the following variables reflect their purpose:
$AppDescription=’Really Cool HSG App’
$AppPublisher=’Hey Scripting Guys’
$CMApp=New-CmApplication –name $AppName –Description $AppDescription –Publisher $AppPublisher –SoftwareVersion $AppVersion –ReleaseDate $AppReleaseDate –Autoinstall:$True
The next piece is to add our deployment. For this example, we’re going to work with a simple MSI file:
Add-CMDeploymentType -MsiInstaller -ApplicationName $AppName –AutoIdentifyFromIntallationFile -InstallationFileLocation $SourcePath -ForceForUnknownPublisher $True
This provides us with a basic application with automatic detection for MSI.
I could probably spend almost another week talking about these cmdlets. I’ve not even touched on adding the packages or applications to distribution groups. We could even delve into writing the custom scripts needed to detect non-MSI applications.
I hope you have discovered that you can get some basic automation done with your Configuration Manager environment—perhaps enough to get you home a bit earlier!
TR, that is all there is to using the Configuration Manager cmdlets for this week.
I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.
Sean Kearney, Honorary Scripting Guy and Cloud and Datacenter Management MVP