{"id":74721,"date":"2015-11-20T00:01:00","date_gmt":"2015-11-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/11\/20\/powershell-and-configuration-manager-2012-r2part-5\/"},"modified":"2019-06-18T23:27:02","modified_gmt":"2019-06-19T07:27:02","slug":"powershell-and-configuration-manager-2012-r2part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-5\/","title":{"rendered":"PowerShell and Configuration Manager 2012 R2\u2013Part 5"},"content":{"rendered":"<p><b style=\"font-size: 12px;\">Summary<\/b><span style=\"font-size: 12px;\">: Use the Configuration Manager cmdlets to create an application.<\/span><\/p>\n<p>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\u2026er\u2026*Cough*&#8230;HELP!<\/p>\n<p>\u2014TR<\/p>\n<p>Hello TR,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today to help you. I know vividly what you\u2019re talking about. I\u2019ve had to do the same thing.<\/p>\n<p><strong> \u00a0Note<\/strong>\u00a0\u00a0This is a five-part series that includes the following posts:<\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Configuration Manager 2012 R2\u2013Part 1<\/a>\nLoad the Configuration Manager cmdlets and make a basic site connection.<\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-2\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Configuration Manager 2012 R2\u2013Part 2<\/a>\nUse the Configuration Manager cmdlets to work with site collections.<\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-3\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Configuration Manager 2012 R2\u2013Part 3<\/a>\nUse the Configuration Manager cmdlets to update applications in distribution points.<\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-4\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Configuration Manager 2012 R2\u2013Part 4<\/a>\nUse the Configuration Manager cmdlets to work with driver packages.<\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/powershell-and-configuration-manager-2012-r2part-5\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell and Configuration Manager 2012 R2\u2013Part 5<\/a>\nUse the Configuration Manager cmdlets to create an application.<\/li>\n<\/ul>\n<p>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.<\/p>\n<p>So first, let\u2019s see the pile of cmdlets you have to work with:<\/p>\n<p style=\"margin-left: 30px;\">Get-Command \u2013module configurationmanager *Application*<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/7888.1.PNG\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/7888.1.PNG\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>This list is quite impressive. There appears to be almost nothing we can\u2019t do with applications. If you look at yesterday&#8217;s post, there is an equally strong pile for creating software packages.<\/p>\n<p>After looking at this pile, my thought is, &#8220;Why would anyone repeatedly use the GUI?&#8221;<\/p>\n<p>Let&#8217;s script it all!<\/p>\n<p>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:<\/p>\n<p style=\"margin-left: 30px;\">Get-CmApplication | Select-Object LocalizedDisplayName<\/p>\n<p>Or to see all of the available packages, use:<\/p>\n<p style=\"margin-left: 30px;\">Get-CmApplication | Select-Object Name<\/p>\n<p>To create a new software package requires two cmdlets, <b>New-CmPackage<\/b> and <b>New-CmProgram<\/b>.<\/p>\n<p><b>New-CmPackage<\/b> creates the base package. Much like the GUI, there is a lot of information you can provide, but only certain bits are actually required.<\/p>\n<p>If you want to create a basic package with the source files on a server file share that targets a user (pretty typical), you\u2019d execute <b>New-CmPackage<\/b> in this fashion:<\/p>\n<p style=\"margin-left: 30px;\">$SourcePath=\u2019ContosoSCCM\\SccmShare\\HSGProgram\u2019<\/p>\n<p style=\"margin-left: 30px;\">$PackageName=\u2019HSG Cool Program\u2019<\/p>\n<p style=\"margin-left: 30px;\">$PackageDescription=\u2019Some amazing App written by the PowerShell Community\u2019<\/p>\n<p style=\"margin-left: 30px;\">$Manufacturer=\u2019Zaphod Beeblebrox\u2019<\/p>\n<p style=\"margin-left: 30px;\">$Language=\u2019GargleBlaster\u2019<\/p>\n<p style=\"margin-left: 30px;\">$Version=\u20191.2\u2019<\/p>\n<p style=\"margin-left: 30px;\">$CMPackage=New-CmPackage \u2013Name $Packagename \u2013Description $PackageDescription \u2013Manufacturer $Manufacturer \u2013Language $Language \u2013Version $Version \u2013Path $SourcePath<\/p>\n<p>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.<\/p>\n<p>If you were to type <b>$CMPackage.PackageID<\/b>, you\u2019d see a familiar piece of information on your screen! The very ID we normally see in the Configuration Manager console.<\/p>\n<p>We can now run <b>New-CmProgram<\/b> and create a launch for this application. We\u2019ll presume the application that launches it is called setup.exe, and we\u2019ll give it an appropriate name:<\/p>\n<p style=\"margin-left: 30px;\">$ProgramCommand=\u2019setup.exe\u2019<\/p>\n<p style=\"margin-left: 30px;\">$ProgramName=\u2019HSG program\u2019<\/p>\n<p style=\"margin-left: 30px;\">$DiskSpace=\u201910\u2019<\/p>\n<p style=\"margin-left: 30px;\">$DiskspaceUnit=\u2019GB\u2019<\/p>\n<p style=\"margin-left: 30px;\">$Runtype=\u2019Normal\u2019<\/p>\n<p style=\"margin-left: 30px;\">$RunMode=\u2019RunWithAdministrativeRights\u2019<\/p>\n<p style=\"margin-left: 30px;\">$CMProgram=New-CMProgram \u2013Commandline $ProgramCommand \u2013PackageID $CMPackage.PackageID \u2013StandardProgramName $ProgramName \u2013DiskSpaceRequirements $DiskSpace \u2013Diskspaceunit $DiskSpaceUnit \u2013RunType $RunType \u2013RunMode $RunMode<\/p>\n<p>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 <b>Suppress program notifications<\/b> option. You could go to the GUI for this, but we can add the <b>Set-CmProgram<\/b> cmdlet to the script in question. We supply the package ID and the name of the program as the key parameters:<\/p>\n<p style=\"margin-left: 30px;\">Set-CmProgram \u2013PackageID $CMPackage.PackageID \u2013ProgramName $CmProgram.ProgramName<\/p>\n<p>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.<\/p>\n<p>The first part is to create the entry in the application list for our custom app. Most of the following variables reflect their purpose:<\/p>\n<p style=\"margin-left: 30px;\">$AppName=\u2019HSG App\u2019<\/p>\n<p style=\"margin-left: 30px;\">$AppDescription=\u2019Really Cool HSG App\u2019<\/p>\n<p style=\"margin-left: 30px;\">$AppPublisher=\u2019Hey Scripting Guys\u2019<\/p>\n<p style=\"margin-left: 30px;\">$AppVersion=\u20191.1\u2019<\/p>\n<p style=\"margin-left: 30px;\">$AppReleaseDate=\u201911\/20\/2015\u2019<\/p>\n<p style=\"margin-left: 30px;\">$AutoInstall=$True<\/p>\n<p style=\"margin-left: 30px;\">$AppOwner=\u2019MrEd\u2019<\/p>\n<p style=\"margin-left: 30px;\">$CMApp=New-CmApplication \u2013name $AppName \u2013Description $AppDescription \u2013Publisher $AppPublisher \u2013SoftwareVersion $AppVersion \u2013ReleaseDate $AppReleaseDate \u2013Autoinstall:$True<\/p>\n<p>The next piece is to add our deployment. For this example, we\u2019re going to work with a simple MSI file:<\/p>\n<p style=\"margin-left: 30px;\">$SourcePath=\u2019ContosoSCCM\\SccmShare\\HSGProgram\\HSGapp.Msi\u2019<\/p>\n<p style=\"margin-left: 30px;\">Add-CMDeploymentType -MsiInstaller -ApplicationName $AppName \u2013AutoIdentifyFromIntallationFile -InstallationFileLocation $SourcePath -ForceForUnknownPublisher $True<\/p>\n<p>This provides us with a basic application with automatic detection for MSI.<\/p>\n<p>I could probably spend almost another week talking about these cmdlets. I\u2019ve 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.<\/p>\n<p>I hope you have discovered that you can get some basic automation done with your Configuration Manager environment\u2014perhaps enough to get you home a bit earlier!<\/p>\n<p>TR, that is all there is to using the Configuration Manager cmdlets for this week.<\/p>\n<p>I invite you to follow the Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\" rel=\"noopener noreferrer\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\" rel=\"noopener noreferrer\">Facebook<\/a>. If you have any questions, send email to them at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\" rel=\"noopener noreferrer\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\" rel=\"noopener noreferrer\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.<\/p>\n<p><b>Sean Kearney, <\/b>Honorary Scripting Guy and Cloud and Datacenter Management MVP<span style=\"font-size: 12px;\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2026er\u2026*Cough*&#8230;HELP! \u2014TR Hello TR, Honorary [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[487,56,154,45],"class_list":["post-74721","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-configuration-manager","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>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\u2026er\u2026*Cough*&#8230;HELP! \u2014TR Hello TR, Honorary [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/74721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=74721"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/74721\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=74721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=74721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=74721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}