Creating an SCCM 2012 Application with PowerShell

With SCCM 2007 it was easy to import a package with PowerShell. For now it is a little bit tricky to accomplish it. In this post I will try to explain how you can create an application in SCCM 2012. This has been tested with the Release Candidate 2.

To create an application with powershell first you have to install the Admin Console. And load assemblies in your powershell script.

function Import-SCCMAssemblies($SCCMAdminConsolePath){
$path = "$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement.dll"
if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)}

$path = "$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement.Extender.dll"
if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)}

$path = "$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement..MsiInstallerdll"
if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)}
}

Next step is to get the ScopeID of you SCCM Site server. How to do this can be found in my previous blog

Now you can create an application XML file with the use of the assemblies we have loaded

    #Loading Assemblies to create an SCCM 2012 application
    Import-SCCMAssemblies "D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\"
    
    #Get Authoring ScopeID 
    $scopeid = Get-AuthoringScopeID $con
     
    #Create an unique id for the application and the deployment type
    $newApplicationID = "Application_" + [guid]::NewGuid().ToString() 
    $newDeploymentTypeID = "DeploymentType_" + [guid]::NewGuid().ToString()     
     
    #Create SCCM 2012 object id for application and deploymenttyo 
    $newApplicationID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newApplicationID)   
    $newDeploymentTypeID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid , $newDeploymentTypeID) 
        
    #Create all the objects neccessary for the creation of the application
    $newApplication =  New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Application($newApplicationID)    
    $newDeploymentType = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,"MSI")
    $newDisplayInfo  =  New-Object Microsoft.ConfigurationManagement.ApplicationManagement.AppDisplayInfo 
    $newApplicationContent = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.Content
    $newContentFile = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.ContentFile
     
    #Setting Display Info
    $newDisplayInfo.Title = $Application.DisplayName
    $newDisplayInfo.Language = $newApplication.DisplayInfo.DefaultLanguage
    $newDisplayInfo.Description = $Application.DisplayName
    $newDisplayInfo.Version = $Application.PRVersion 
    $newApplication.DisplayInfo.Add($newDisplayInfo)

    #Setting default Language must be set and displayinfo must exists
    $newApplication.DisplayInfo.DefaultLanguage = "en-US"


    $newApplication.Title = $APP.Title
    $newApplication.Version = 1
    
    #Deployment Type msi installer will be used
    $newDeploymentType.Title = "Deploy $($APP.DisplayName)"
    $newDeploymentType.Version = 1 
    $newDeploymentType.Installer.ProductCode = $APP.ProductCode 
    $newDeploymentType.Installer.InstallCommandLine = "Msiexec /i $($APP.MSIName) /qb-! Reboot=ReallySuppress"
    $newDeploymentType.Installer.InstallFolder  ="\"  
    $newDeploymentType.Installer.UninstallCommandLine = "Msiexec /x $($APP.ProductCode) /qb-! Reboot=ReallySuppress" 

    #Add the msi as content to the application

    #UPDATE: Add all content to the application
    $newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($APPUNCPath)

        #DELETE: $newContentFile.Name = $APP.MSIName
        #DELETE: $newApplicationContent.Files.Add($newContentFile)
        #DELETE: $newApplicationContent.Location = $APP.UNCPath
        $newApplicationContent.OnSlowNetwork = "Download"



    $newDeploymentType.Installer.Contents.Add($newApplicationContent )
    $newApplication.DeploymentTypes.Add($newDeploymentType)
 
    #Serialize the object to an xml file
    $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)

So now we have an XML file with the data of the application. In this example we use an msi file. It is also possible to use a script or executable. then you have to set the deployment type to Script. Next step is to import the xml file.

        $applicationClass = [WMICLASS]"\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Application"
        $newApplication = $applicationClass.createInstance() 
        
        $newApplication.SDMPackageXML = $newApplicationXML 
        $tmp = $newApplication.Put()
        
        #Reload the application to get the daat 
        $newApplication.Get()
 

Now we have created an application in SCCM 2012 with the use of PowerShell. The next step is to distribute and deploy the application to a collection.

52 thoughts on “Creating an SCCM 2012 Application with PowerShell”

  1. looks nice but not compleate i give them a quick try possibly this is what i need to automate application deployment. the xml in my try was not created i’m not so familiar with powershell.

    1. Let me know if it works. Otherwise post or mail your script and I will take a look at it.

  2. thx for the verry fast answer do you have me a powersehll example that create an application xml file directly it looks for me i have a sccm connection problem in my homelab.

    1. Becuase of eastern a little late response. But the code that creates the xml file is
      $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)

      This line serialize an object ($newApplication) to an xml string

  3. Thx for answer after a while playing around with many try & error i got it… so i understand what to do to create the app. but for me thats only the begining…

  4. This piece of code doesn’t seem to work for me.

    I got up to the point where I try to enter in my $newApplication.Put() but I keep getting a generic error.

    Any ideas what I could be doing wrong?

    1. First you can check the xml file if it created the correct file and nothing is missing. You can also check the server log where you can find why it wasn’t able to create the application.

  5. Hi

    Thank you very much for this great post! I noticed that in the final version of SCCM 2012 the Extender.dll and MsiInstaller.dll assemblies are missing. Hence I am unable to create the deployment types.

    Do you have any idea how to do that now, or am I facing an corrupt installation?

    Thx!

    1. Hi,
      I cannot verify it now but I use this script also with the SCCM 2012 RTM version so I guess you’re facing a corrupt installation. These files needs be present with the SCCM Admin Console. It’s can also be possible that these files are obsolete but I guess thats not the case. I will let you know when i have check it.

      Greetz Rob

  6. Hi,

    This is exactly what I’ve been looking for the last few months!

    Unfortunately, just like calldor, my Powershell skills are limited. I can’t get the script to run.

    It seems the code isn’t complete? My computer doesn’t recognise the Get-AuthoringScopeID command.

    Could anybody please provide a complete working script?

    Thanks!

    1. Hi Scott,

      It is indeed not a complete working script. This is becuase I use multiple Powershell Modules. I will post a new blog item where you can find more information. Including the function Get-AuthoringScopeID.

      Grtz Rob

    2. Hi Scott,
      Below you can find the function to get the authoring scope.

      [powershell]

      Function Get-AuthoringScopeID{
      [CmdletBinding()]
      PARAM (
      [Parameter(Mandatory=$true, HelpMessage=”SCCM Server”)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer
      )

      PROCESS {
      $identificationClass = [WMICLASS]”\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Identification”
      $cls = Get-WmiObject SMS_Identification -namespace $SccmServer.Namespace -ComputerName $SccmServer.Machine -list
      $tmp = $identificationClass.GetSiteID().SiteID
      return “ScopeId_$($tmp.Substring(1,$tmp.Length -2))”
      }
      }

      [/powershell]

  7. Hi Rob,

    We want to install (or call) a application which is published for “All Users” under Config Manager 2012 application catalog via a script or hta code.

    We want to achive, when a user clicks on a URL, it will install the published application from application catalog.

    How to do this? Please help.

    (Reposting under Application Management section)

    TIA

    1. Hi Saravanan,
      Currently there isn’t a supported way to do this. The Silverlight App uses the webservice http:///CMApplicationCatalogsvc to install the application. Because there is no SDK for this service it is difficult to create your own website. I will try to make it possible because it would be a great way to customize the Application Catalog. If I found something I will blog about it.

      greetz Rob

  8. Hello and many thanks for the great post !!!
    As you have already told, after creating an application, it would be time to deploy the application to a collection. It’s clear for me how to create an advertisement to deploy a package, but i found nothing related how to deploy the application. Some ideas?
    Thank you in advance!
    Alex

    1. Hi Alex,

      Nice to here you like the post. I should have posted the deploy step. But because we are in the middle of a Windows 7 deployment with SCCM 2012 for a large customer (+10K). I didn’t had the time to do this. This week I will post the new blog post.

      Rob

      1. Hello Rob,

        I will double check, maybe I just overlooked the deployment post.
        Otherwise I’ll wait. 🙂
        Thanks a lot for your effort to post those great hints and advisories.

        Alex

        1. Hi Alex,

          I finally made the blog post about deploying an application. If you have questions about it just comment the blog post.

          Gr Rob

  9. I want to echo how helpful your site and examples are, they’re great. You seem to have run across many of the things the rest of us are now facing.

    I’m wondering if you have any examples for Detection Methods, such as the existence of a file? Or for Requirement Rules, such as disk space or OS?

    1. For now I don’t have any example but you can find an example at the following website (). Although this is C# it is easy to make an PowerShell script from it. Except the line: RegistrySetting registrySetting = new RegistrySetting(null); because of a bug in powershell (I think). Next week I will create a blog post about this.

      If you still have question about detection method or requirements please ask.

  10. Hi,

    I would like to create an application in SCCM 2012 through powershell by using only WMI Classes and i don’t want to use .NET classes. Do you have any script written for that? or any Idea how to do that?

    Thanks,
    Vedayaj

    1. Hi Vedayaj,
      As you can see in this post I used wmi classes and a XML file to create an application. If you don’t want to use the .Net class to create the XML file you have to manually create the xml file. But why don’t you want to use the script I post.

      Greets,
      Rob

      1. Hi Rob,

        We are actually running the powershell scripts from a remote machine, so our concern is that the customer would not be interested to install the AdminConsole on that machine and also shipping the DLLs might be a problem for us.
        I was able to create an application by creating the xml file manually, but we don’t want any manually created objects in our code.

        Thanks,
        Vedayaj

        1. You could use a dummy application where you retrieve its XML file. But as far as I know there isn’t a WMI object that you can fill in to create the application. You have to have an XML file that needs to be added to an instance of the SMS_Application class.

    1. Do you mean a script that creates an application that doesn’t have a msi to install. Like a setup.exe? I have worked on a script that creates a registry detection method but isn’t finsihed yet.

      1. There is an option in SCCM 2012 to create an application by detection i.e. by just providing an msi file and sccm will automatically determine the deployment type and all. I wanted to develop a script for that method.

        1. This scripts makes an application with detecteion for a msi. For other file types I didn’t create a script because there are many ways of detection. So if you want to use only msi my script is a good start. Which other installation types do you want to add as an application installation?

  11. Hi Rob,

    I am trying to create application using remote invocation of the above script, but during that process we were facing some problem with the Put() command. I think this command is not working because of which the application is not getting created. Could you help me find the solution for this problem.

    Thanks,
    Vedayaj

    1. Does your script work if you run it on the site server? You can check the log on the site server there you can find a detailed exception.

        1. Can you compare the XML files created in the two scenario’s. Otherwise you have to check the logs on the site server. When te error occurs it should give you detailed information.

  12. Hi,
    As I’m new to the powershell I dont know how to use above code for creating the application in SCCM 2012 server.The code for loading assemblies worked fine for me when i ran in sccm server. But the code for getting the scope ID(Previous blog) throwing me below error. I’m just copying the code in Windows powershell ISE of SCCM server and running it. Can you please tell me how should I use this code step by step to create application as i dont understand the code.

    Error Description:

    Cannot convert value “\\\:SMS_Identification” to type “System.Management.ManagementClass”. Error: “Invalid parameter ”
    At line:1 char:34
    + $identificationClass = [WMICLASS] <<<< "\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Identification"
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

    Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command
    again.
    At line:2 char:87
    + $cls = Get-WmiObject SMS_Identification -namespace $SccmServer.Namespace -ComputerName <<<< $SccmServer.Machine -list
    + CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    You cannot call a method on a null-valued expression.
    At line:3 char:38
    + $tmp = $identificationClass.GetSiteID <<<< ().SiteID
    + CategoryInfo : InvalidOperation: (GetSiteID:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:4 char:15
    + $tmp.Substring <<<< (1,$tmp.Length -2)
    + CategoryInfo : InvalidOperation: (Substring:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    ScopeId_

    1. Hi Prad,
      As a start I used the SCCM module you can find at http://www.snowland.se/2010/03/10/sccm-module-for-powershell/

      with this module I create a object named $SccmServer. because you don;t have the object the following code will not work.

      $identificationClass = [WMICLASS]”\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Identification”

      you can change this in
      $identificationClass = [WMICLASS]”\\SCCMSERVER\root\sms\site_s01:SMS_Identification”
      replace SCCMSERVER with the name of the server and S01 with your site ID.

      1. Hi Rob,
        Thanks for your swift reply. Getting the scope ID is working for me now. So I tried generating the XML and creating the application.I’m not getting any error as such.But the Application is not created.Can you please let me knw, what is the location of XML file generated?Can you please tell me what could be the possible reason of failure by seeing the below code?Scope ID I got is “654A2DAA-66A2-4418-B5E1-8B239C32423E”.

        Code:

        $SCCMAdminConsolePath=”C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole”

        function Import-SCCMAssemblies($SCCMAdminConsolePath){
        $path = “$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement.dll”
        if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)}
        $path = “$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement.Extender.dll”
        if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)}
        $path = “$SCCMAdminConsolePath\Microsoft.ConfigurationManagement.ApplicationManagement..MsiInstallerdll”
        if (Test-Path $path) { $t = [System.Reflection.Assembly]::LoadFrom($path)} }

        $identificationClass = [WMICLASS]“\\SCCM2012QA\root\sms\site_LOL:SMS_Identification”
        #$identificationClass = [WMICLASS]”\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Identification”
        $cls = Get-WmiObject SMS_Identification -namespace $SccmServer.Namespace -ComputerName SCCM2012GA -list
        $tmp = $identificationClass.GetSiteID().SiteID
        return “ScopeId_$($tmp.Substring(1,$tmp.Length -2))”

        #Loading Assemblies to create an SCCM 2012 application
        Import-SCCMAssemblies “C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole”
        #Get Authoring ScopeID
        $scopeid = “654A2DAA-66A2-4418-B5E1-8B239C32423E”
        #Create an unique id for the application and the deployment type
        $newApplicationID = “Application_” + [guid]::NewGuid().ToString()
        $newDeploymentTypeID = “DeploymentType_” + [guid]::NewGuid().ToString()
        #Create SCCM 2012 object id for application and deploymenttyo
        $newApplicationID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newApplicationID)
        $newDeploymentTypeID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid , $newDeploymentTypeID)
        #Create all the objects neccessary for the creation of the application
        $newApplication = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Application($newApplicationID)
        $newDeploymentType = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,”MSI”)
        $newDisplayInfo = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.AppDisplayInfo
        $newApplicationContent = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Content
        $newContentFile = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ContentFile
        #Setting Display Info
        $newDisplayInfo.Title = “Firefox”
        $newDisplayInfo.Language = “English”
        $newDisplayInfo.Description = “Firefox”
        $newDisplayInfo.Version = “1.0”
        $newApplication.DisplayInfo.Add($newDisplayInfo)
        #Setting default Language must be set and displayinfo must exists
        $newApplication.DisplayInfo.DefaultLanguage = “en-US”

        $newApplication.Title = “Firefox”
        $newApplication.Version = 1
        #Deployment Type msi installer will be used $newDeploymentType.Title = “Deploy $($APP.DisplayName)”
        $newDeploymentType.Version = 1
        $newDeploymentType.Installer.ProductCode = “{5F85D8DB-1444-4D0B-B807-694F8F01C793}”
        $newDeploymentType.Installer.InstallCommandLine = “Msiexec /i Firefox /qb-! Reboot=ReallySuppress”
        $newDeploymentType.Installer.InstallFolder =”\”
        $newDeploymentType.Installer.UninstallCommandLine = “Msiexec /x {5F85D8DB-1444-4D0B-B807-694F8F01C793} /qb-! Reboot=ReallySuppress”
        #Add the msi as content to the application
        #UPDATE: Add all content to the application
        $APPUNCPath=”\\178.26.82.6\sms_site\Firefox.msi”
        $newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($APPUNCPath)
        #DELETE: $newContentFile.Name = $APP.MSIName
        #DELETE: $newApplicationContent.Files.Add($newContentFile)
        #DELETE: $newApplicationContent.Location = $APP.UNCPath

        $newApplicationContent.OnSlowNetwork = “Download”
        $newDeploymentType.Installer.Contents.Add($newApplicationContent )
        $newApplication.DeploymentTypes.Add($newDeploymentType)
        #Serialize the object to an xml file
        $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)
        $applicationClass = [WMICLASS]“\\SCCM2012QA\root\sms\site_LOL:SMS_Application”
        $newApplication = $applicationClass.createInstance()
        $newApplication.SDMPackageXML = $newApplicationXML
        $tmp = $newApplication.Put()
        #Reload the application to get the daat
        $newApplication.Get()

        1. with the following line an xml string is created from the object
          $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)

          So if you parse the string $newApplicationXMl you can examine the object you created. If you send me the output of that variable I can examine what the problem is.

  13. I’ve been able to successfully create an application within SCCM 2012 (SP1) and also setup a registry detection rule using a workaround due to a bug related to the registry (details here http://social.technet.microsoft.com/Forums/en-US/configmanagersdk/thread/93bddee4-6aee-4641-b104-170968ad1549/).

    Anyways, the app gets created in SCCM but it won’t install, it fails. The details are in the AppEnforce basically we have “Invalid data file install.vbs to execute using file association. PrepareCommandlin failed, etc. etc.”.

    Exporting the app out and looking at the object.xml within the zip file and comparing it with the same app but created manually in the console, it appears that there is something missing. For example, a “bad” app that refuses to install, this is in the object.xml:

    MSI

    …..

    But in a good working package, we have this instead:

    MSI

    …..

    At a high level I do this:

    $newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($UNCPath)
    $newDeploymentType.Installer.InstallCommandLine = “$($Install)”
    $newDeploymentType.Installer.UninstallCommandLine = “$($Uninstall)”

    $newApplication.DeploymentTypes.Add($newDeploymentType)

    I’m at a loss at what’s is missing here as the content ID isn’t part of the InstallAction and UninstallAction, thus the SCCM client has no idea where it should go to run the commands.

    The workaround I have is basically obtaining the content ID and version further up in the object.xml and then inserting it before the and . It works but would like to do this properly vs editing the XML after the fact.

      1. One further question, do you have any idea how to populate the owner and support contact? I see that they are properties of the application class but unsure how to store this information, as it appears to be in a list structure (my powershell skills are at what I would call an amateur level right now)

        1. You can use the following command to add administrator as the owner:
          $newUser = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.User
          $newUser.Qualifier = “LogonName”
          $newuser.id = “Administrator”
          $newApplication.Owners.Add($newUser)

  14. Was anyone ever able to add a Global Condition to a requirement rule? I believe I’m very close (I can share the code if anyone is interested), but when I attempt the put method after re-serializing the XML, I receive a ‘Generic failure’ error, with no further details.

  15. hi there, thanks for this post. This is a great process. I am having an issues with the serialization, I get the following error:

    Exception calling “SerializeToString” with “2” argument(s): “Invalid property: object
    Application(ScopeId_3FB0A58D-16C5-4012-A53E-B027B6658BB3:Application_7baca021-63dd-4b28-a0f8-ebc5e252dde2:1) property DisplayInfo.DisplayInfo.DefaultLanguage: Language en-US does not match
    any data in the set”
    At line:1 char:1
    + $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Se …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidPropertyException

    1. Do you have some sample code…
      Maybe it is because you use a different displayinfo language then en-US ??

  16. Sure, here is the code:

    Import-Module .\Modules\SCCM2012-Commands.psm1
    Import-Module .\Modules\SCCM-Commands.psm1
    $con = Connect-SCCMServer ########
    Get-AuthoringScopeID $con

    ########
    #Loading Assemblies to create an SCCM 2012 application
    ########
    Import-SCCMAssemblies “E:\SCCM\AdminConsole\bin\”

    #Get Authoring ScopeID
    $scopeid = Get-AuthoringScopeID $con

    #Create an unique id for the application and the deployment type
    $newApplicationID = “Application_” + [guid]::NewGuid().ToString()
    $newDeploymentTypeID = “DeploymentType_” + [guid]::NewGuid().ToString()

    #Create SCCM 2012 object id for application and deploymenttyo
    $newApplicationID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newApplicationID)
    $newDeploymentTypeID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid , $newDeploymentTypeID)

    #Create all the objects neccessary for the creation of the application
    $newApplication = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Application($newApplicationID)
    $newDeploymentType = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,”MSI”)
    $newDisplayInfo = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.AppDisplayInfo
    $newApplicationContent = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Content
    $newContentFile = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ContentFile

    #Setting Display Info
    $newDisplayInfo.Title = “Flash Player”
    $newDisplayInfo.Language = “English”
    $newDisplayInfo.Description = “Flash Player”
    $newDisplayInfo.Version = “11”
    $newApplication.DisplayInfo.Add($newDisplayInfo)

    #Setting default Language must be set and displayinfo must exists
    $newApplication.DisplayInfo.DefaultLanguage = “en-US”

    $newApplication.Title = “Flash Player 11”
    $newApplication.Version = 1

    #Deployment Type msi installer will be used
    $newDeploymentType.Title = “Deploy $($APP.DisplayName)”
    $newDeploymentType.Version = 1
    $newDeploymentType.Installer.ProductCode = “{2F84A256-83AA-47A5-BCC1-E5CDB35B3F56}”
    $newDeploymentType.Installer.InstallCommandLine = “Msiexec /i install_flash_player_11_active_x /qb-! Reboot=ReallySuppress”
    $newDeploymentType.Installer.InstallFolder =”\”
    $newDeploymentType.Installer.UninstallCommandLine = “Msiexec /x {2F84A256-83AA-47A5-BCC1-E5CDB35B3F56} /qb-! Reboot=ReallySuppress”

    #Add the msi as content to the application
    #UPDATE: Add all content to the application
    $APPUNCPath=”\\######\e$\Dist1\Flash Player”
    $newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($APPUNCPath)

    #DELETE: $newContentFile.Name = $APP.MSIName
    #DELETE: $newApplicationContent.Files.Add($newContentFile)
    #DELETE: $newApplicationContent.Location = $APP.UNCPath
    $newApplicationContent.OnSlowNetwork = “Download”

    $newDeploymentType.Installer.Contents.Add($newApplicationContent )
    $newApplication.DeploymentTypes.Add($newDeploymentType)

    #Serialize the object to an xml file
    $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)

    $applicationClass = [WMICLASS]”\\$($SccmServer.Machine)\$($SccmServer.Namespace):SMS_Application”
    $newApplication = $applicationClass.createInstance()

    $newApplication.SDMPackageXML = $newApplicationXML
    $tmp = $newApplication.Put()

    #Reload the application to get the daat
    $newApplication.Get()

    Where can I validate the displayinfo?

  17. Hi,

    I wanted to connect with you. Seen a lot of your posts. So asking you for your advice.

    Requirement – I have to create an application of the below PowerShell script and run this script in admin mode in SCCM 2012 as a dependency with my UE-V Agent application (this msi package has been tested successfully).

    Now how do I create an application of the below program and run this program in powershell admin mode in SCCM 2012. Should I do it with a small task sequence or should I use simple dependency feature. Request you to please advise.

    Program –

    $exists = Test-Path HKLM:\SYSTEM\CurrentControlSet\Services\CSC

    if ($exists)
    {

    $startvalue = get-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\CSC | foreach {$_.Start}
    if ($startvalue -eq 4)
    {
    set-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\CSC -Name Start -Value 1
    set-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\CscService -Name Start -Value 2
    }
    }

    $exists = Test-Path HKLM:\SYSTEM\CurrentControlSet\Services\CscService

    if ($exists)
    {
    $startvalue = get-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\CSCService | foreach {$_.Start}

    if ($startvalue -eq 4)
    {
    set-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\CSCService -Name Start -Value 2
    set-itemproperty HKLM:\SYSTEM\CurrentControlSet\Services\Csc -Name Start -Value 1
    }
    }

    1. The program you showed is, according to SCCM not, an application. You cannot determine if it is installed. There are more options but I prefer one of the following.
      * . Change script to also add a registry key. Create an application with this script. Install program will be “powershell.exe -file “script.ps1” and run as system. Check for the key if the application is installed. Add as dependancy to UE-V agent.
      * Change/create installation script of UE-V agent and include this script.

Comments are closed.