ConfigMgr: Applikationserstellung mit Powershell

Möchte man per Powershell neue Applikationen im ConfigMgr erstellen, so ist dies mittels New-C;Mpplication und Add-CMDeploymentType relativ einfach machbar. Der passende TechNet Artikel (http://technet.microsoft.com/en-us/library/jj870953%28v=sc.20%29.aspx) listet alle verfügbaren Parameter auf. Microsoft hat leider versucht, mit einem Powershell Kommando alle möglichen Deployment Types abzudecken. Gerade im Bereich Scripted Installed (Manual Deployment Type) ist korrekte Zusammenstellung schwierig.

Nachfolgend wird daher ein Beispiel für eine Verteilung einer Anwendung (in diesem Fall aus dem Powershell App Deployment Toolkit), die im Hintergrund ein MSI File installiert. Die Anwendungserkennung soll auf Basis des MSI Produktcodes und der entsprechenden Version erfolgen. Es ist nach meinen Recherchen nicht möglich, per Powershell die eingebauten Detection-Methoden (MSI, File, Directory oder Registry-Werte) zu verwenden. Daher muss diese Funktion mittels einer Powershell Zeile nachgebaut werden.

Zuerst wird eine neue Application erstellt:

$app=New-CMApplication –Name "Testanwendung" -Description "Created by automateAppDeployment from mbaeker.de" –SoftwareVersion "1.0" -AutoInstall $true

Im nächsten Schritt wird das Detectionscript definiert:

$script="Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where {$_.psChildname -like `"{0000-0000-0000-0000}`" -and $_.DisplayVersion -eq `"1.0.0.0`" -and $_.WindowsInstaller -eq 1}"

Das Script sucht in der Registry im Uninstall Bereich nach einem Unterschlüssel, der dem Productcode entspricht. Darin muss zusätzlich die passende Version hinterlegt sein. Als Zusatzkriterium wird überprüft, ob es sich bei dem Uninstall Eintrag um einem vom Windows Installer erstellten Wert handelt.

Da für den Deployment Type sehr viele Parameter erforderlich sind, wird ein Property Hash mit allen Parametern erstellt. Dies fördert die Übersichtlichkeit:

    $DeploymentTypeHash = @{
                    ApplicationName = "Testanwendung"
                    DeploymentTypeName = "AppDeploy Testanwendung"
                    ScriptInstaller = $true
                    ManualSpecifyDeploymentType=$true
                    DetectDeploymentTypeByCustomScript = $true
                    ScriptType = 'Powershell'
                    ScriptContent = $script
                    AdministratorComment = "Created by automateAppDeployment from mbaeker.de"
                    ContentLocation = "\\cm01\ConfigMgr\Content\Software\Testanwendung"
                    InstallationProgram ='deploy-application.exe'
                    UninstallProgram ='deploy-Application.EXE -DeploymentType "Uninstall"'
                    RequiresUserInteraction = $false
                    InstallationBehaviorType = 'InstallForSystem'
                    InstallationProgramVisibility = 'Normal'
                    LogonRequirementType = 'WhereOrNotUserLoggedOn'
                    }

Im letzten Schritt wird die Verteilmethode mit den angegebenen Werten zur Anwendung hinzugefügt:

Add-CMDeploymentType @DeploymentTypeHash

Das Ergebnis ist eine Neue Anwendung mit einem scriptbasiertem Deployment Type und einer scriptbasierten Erkennung:

Testanwendung-PS

 

This entry was posted in Configuration Manager, Deutsch, Powershell, System Center, System Center 2012 and tagged , , , , . Bookmark the permalink.

3 Responses to ConfigMgr: Applikationserstellung mit Powershell

  1. Torsten says:

    “Es ist nach meinen Recherchen nicht möglich, per Powershell die eingebauten Detection-Methoden (MSI, File, Directory oder Registry-Werte) zu verwenden. ” –> doch geht, aber nur extrem komplex und nicht mit den cmdlets.

    • markus says:

      Stimmt. Da war meine Aussage etwas vereinfacht. Über WMI gibt es Beschreibung dazu, aber ich erwarte so was eigentlich von den Commandlets.
      Grüße

      Markus

  2. Anbalagan says:

    I have an issue while creating application with Script deployment type.

    I am using the below code to create a script deployment type, script content is not accepting Powershell variable to insert the script content.

    Error message:

    [ERROR] Cannot validate argument on parameter ‘ScriptContent’. The argument is null or empty. Provide an arg
    ument that is not null or empty, and then try the command again.

    $detection= get-content $filelocation

    $DeploymentTypeHash = @{
    ManualSpecifyDeploymentType = $true #Yes we are going to manually specify the Deployment type
    Applicationname = “$ApplicationName” #Application Name
    DeploymentTypeName = “$ApplicationName” #Name given to the Deployment Type
    DetectDeploymentTypeByCustomScript = $true # Yes deployment type will use a custom script to detect the presence of this
    ScriptInstaller = $true # Yes this is a Script Installer
    ScriptType = ‘VBscript’ # yep we will use PowerShell Script
    ScriptContent = “$detection” # Use the earlier defined here string
    ContentLocation = “$source” # NAL path to the package
    InstallationProgram =’install.vbs”‘ #Command line to Run for install
    UninstallProgram =’uninstall.vbs’ #Command line to Run for un-Install
    RequiresUserInteraction = $false #Don’t let User interact with this
    InstallationBehaviorType = ‘InstallForSystem’ # Targeting Devices here
    InstallationProgramVisibility = ‘Hidden’ # Hide the PowerShell Console
    }

    Add-CMDeploymentType @DeploymentTypeHash

    Regards,
    Lavanya

Leave a Reply