Trouble with Add-CMDeploymentType and -ScriptInstaller type

We have a Configuration Manager 2012 SP1 setup and Im trying to populate the system with all our applications by using PowerShell only. I can create device collections, device collection query rules, applications, application deployment types (if msi, appv 4.6 or appv 5), content distributions and deployments. But for some reason I cant get the Add-CMDeploymentType cmdlet to work with the ScriptInstaller parameter.

Example:

Add-CMDeploymentType -ApplicationName "Testapp" -ScriptInstaller -ManualSpecifyDeploymentType -DeploymentTypeName "Acme Testapp 10.4.5 - SCRIPT" -InstallationProgram "install_testapp.cmd" -DetectDeploymentTypeByCustomScript -ScriptType PowerShell -ScriptContent "test-path 'c:\windows'" -AdministratorComment "APP00001" -RunIntallationProgramAs32BitProcessOn64BitClient $false -InstallationBehaviorType InstallForSystem -ContentLocation "\\afs\ltu.se\package\application\APP00001" -RunScriptAs32bitProcessOn64bitClient $false -LogonRequirementType OnlyWhenNoUserLoggedOn

By stripping out everything not necessary I know that it is the ScriptContent parameter that generates the error WARNING: Select a correct parameter set.. I have tried both VBScript and Powershell script types but no matter the value of the ScriptContent I get this error. According to the documentation ScriptContent is of type string.

I find it a bit odd that you can just use scripts for detection methods but I dont mind if I can get it to work. APPV and MSI works just fine but about 66% of our applications use script based installations.

As a last resort I could probably do it the same way as on configuration manager 2007 with WMI and Packages but Id rather move everything over to the application model as we do the migration.


March 12th, 2013 5:13pm

Im getting the same error message (WARNING: Select a correct parameter set.) when trying to add a ScriptInstaller deployment type, so might be a bug in the documentation or in the Add-CMDeploymentType Cmdlet. Another way would be to try the C# code example in the SDK documentation in case you want to go down that path
Free Windows Admin Tool Kit Click here and download it now
March 13th, 2013 8:43am

I've been struggling with the same issue and have not been able to find a combination of parameters that -ScriptInstaller won't choke on and spit up.  It's either bugged or the correct usage is counterintuitive and not fully documented.  I'm still tinkering with it and will post a solution if I ever figure it out but, if it helps, you can specify script installers for the -MsiInstaller method.  Here's a  working command line.

Add-CMDeploymentType -ApplicationName $AppName -DeploymentTypeName $DeploymentTypeName -MsiInstaller -ManualSpecifyDeploymentType -InstallationProgram $InstallScript -UninstallProgram $UninstallScript -ScriptType VBScript -ScriptContent "msgbox 1" -DetectDeploymentTypeByCustomScript -ContentLocation $SourcePath -InstallationBehaviorType InstallForSystem -RunIntallationProgramAs32BitProcessOn64BitClient $true -RunScriptAs32bitProcessOn64bitClient $true -InstallationProgramVisibility Normal -LogonRequirementType WhereOrNotUserLoggedOn -RequiresUserInteraction $false -MaximumAllowedRunTimeMinutes 720

March 13th, 2013 5:07pm

Same problem here - if any of you guys find a solution please let me know. Some faulty documentation wouldn't surprise me. Just take the typo in the cmdlet "Start-CMApplicationDeployment" with the parameter "-AvaliableTime/Date"...
Free Windows Admin Tool Kit Click here and download it now
March 14th, 2013 12:32pm

I sat all day with google and tried out code and at the and I was successful in putting together someting that actually worked. The sample script creates both the application and the deployment type at the same time. I would rather use a prebuilt application and just add the deployment type but that is work for another day. Hope you find it usefull.

I did find a good reference here http://blogs.technet.com/b/chrad/archive/2012/09/12/configmgr-2012-pcm-walking-through-pcm-plug-in-capabilities.aspx but I could not get the DetectionMethod to work in my code. But I got it working with both VBScript and PowerShell detection scripts and I'm fine for now with that.

-------------ExampleCode---------------

#Anders Hannus 2013-03-14
#Some code from: http://blog.lechar.nl/2012/04/03/creating-an-sccm-2012-application-with-powershell/


#Load assemblies
[Reflection.Assembly]::LoadFile("D:\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.ApplicationManagement.dll") | out-null
[Reflection.Assembly]::LoadFile("D:\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.ApplicationManagement.MsiInstaller.dll") | out-null

$wminamespace = "Root\SMS\Site_S02"
$sccmserver = hostname

#Application info. Normaly read from LDAP database but hardcoded in this example.
$LTUappMaker = "LTU"        #Maker of application
$LTUappName = "testapp"        #Name of application
$LTUappVersion = "1.0"        #Version of application
$LTUpackageName = "install_ltukerberos_ltu.cmd"  #Command to install application
$description = "Registry keys so that Windows can find the KRB servers for Realm LTU.SE" #Description of what the program is/does.
$displayname = "TEST testapp 1.0"     #Diplayname, created from LTUappMaker, LTUappName and LTUappVersion but might be adjusted.
$app = "APP00001"         #Application id in our database
$source = "\\server\sccmsource\$app" #Source directory for application.
$LTUappCheckPath = "C:\Windows\notepad.exe"  #file/folder to detect if application is installed.

write-host "Creating Application $displayname"

#Get scopeid
$identificationClass = [WMICLASS]"\\$($sccmserver)\$($wminamespace):SMS_Identification"
$cls = Get-WmiObject SMS_Identification -namespace $wminamespace -ComputerName $sccmserver -list
$tmp = $identificationClass.GetSiteID().SiteID
$scopeid = "ScopeId_$($tmp.Substring(1,$tmp.Length -2))"

#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 deploymenttype
$newApplicationID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newApplicationID) 
$newDeploymentTypeID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newDeploymentTypeID)

#Create objects neccessary for the creation of the application
$newApplication = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Application($newApplicationID)
$newDeploymentType = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,"Script")

#Setting Display Info
$newDisplayInfo = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.AppDisplayInfo
$newDisplayInfo.Title = $displayname
$newDisplayInfo.Language = "sv-SE"
$newDisplayInfo.Description = $description

$newApplication.DisplayInfo.Add($newDisplayInfo)

#Setting default Language must be set and displayinfo must exist
$newApplication.DisplayInfo.DefaultLanguage = $newDisplayInfo.Language
$newApplication.Title = $displayname
$newApplication.Version = 1.0
$newApplication.Publisher = $LTUappMaker
$newApplication.SoftwareVersion = $LTUappVersion
$newApplication.Description = $app

#Add all content to the application
$newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($source)
$newApplicationContent.OnSlowNetwork = "Download"

#Deployment Type Script installer will be used
$newDeploymentType.Title = "$displayname - Script Installer"
$newDeploymentType.Version = 1.0
$newDeploymentType.Installer.InstallCommandLine = $LTUpackageName
$newDeploymentType.Installer.UninstallCommandLine = $LTUpackageName.replace("install","uninstall")
$newDeploymentType.Installer.Contents.Add($newApplicationContent)

#Detectionmethod
$testscript = "if (test-path ""$LTUappCheckPath"") {write-host ""The application is installed.""}"
$newDeploymentType.Installer.DetectionMethod = "Script"
$newDetectionScript = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Script
$newDetectionScript.Language = "PowerShell"
$newDetectionScript.Text = $testscript
$newDeploymentType.Installer.DetectionScript = $newDetectionScript

#Add the DeploymentType to the Application
$newApplication.DeploymentTypes.Add($newDeploymentType)

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

$applicationClass = [WMICLASS]"\\$($sccmserver)\$($wminamespace):SMS_Application"
$newApplication = $applicationClass.createInstance()
 
$newApplication.SDMPackageXML = $newApplicationXML
$tmp = $newApplication.Put()
 
#Reload the application to get the data
$newApplication.Get()

 
March 14th, 2013 7:21pm

Good way of doing this without the PowerShell module, thanks for sharing. To change an existing application you have to call the DeserializeFromString method to de-serialise the XML to an application object (Microsoft.ConfigurationManagement.ApplicationManagement.Application). Use your existing code to add a deployment type ($ApplicationObject.DeploymentTypes.Add()), serialise, set the xml property and save/put the object...

#variables
$SiteCode = "XXX"
$SiteServer = "SERVERNAME"
$ApplicationName = "APPNAME"
$ApplicationVersion = "APPREVISON"
#connection
import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + "\ConfigurationManager.psd1")
Set-Location $SiteCode":"
CD $SiteCode":"
#get application by displayname and revision
$Application = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_Application -ComputerName $SiteServer -Filter "LocalizedDisplayName='$ApplicationName' AND CIVersion=$ApplicationVersion"
#load lazy properties (includes XML)
$Application.Get()
#write XML to variable and print to screen
$ApplicationXML = $Application.SDMPackageXML
Write-Host $ApplicationXML
#deserialize XML to application object
$ApplicationObject = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::DeserializeFromString($ApplicationXML,$true)

Silvan
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2013 2:01am

Even am facing the same problem for ScriptInstaller. MSI and AppV are working fine.
March 18th, 2013 2:45pm

Awesome post.  Thank you!  This is extremely helpful.
Free Windows Admin Tool Kit Click here and download it now
May 11th, 2013 6:37pm

Excellent post.  This clears up my confusion on deserialize/serialize.
May 11th, 2013 6:39pm

The documentation http://technet.microsoft.com/en-us/library/jj870953.aspx has several spelling errors with parameters. "Installation" has been spelt as "Intallation"

for example: "-RunIntallationProgramAs32BitProcessOn64BitClient" should be "-RunInstallationProgramAs32BitProcessOn64BitClient"

It wasn't till I ran get-help Add-CMDeploymentType in powershell that I found that difference.

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2013 8:18am

@sykesy - I did notice the documentation typo because originally I would get an error using "-RunIntallationProgramAs32BitProcessOn64BitClient".  But even when I use the correct syntax, it does not throw an error and appears as if it ran successfully, but when examining the value of -RunInstallationProgramAs32BitProcessOn64BitClient  when set to $True, for me it still does not set that property correctly.  It is still unchecked when I set it to $True.  Just wondering if you see the same thing or if you have it working?
July 8th, 2013 4:00pm

Actually, it looks like -RunInstallationProgramAs32BitProcessOn64BitClient does work OK on Add-CMDeploymentType.  It is Set-CMDeployment type where it does not seem to work.  No errors, just fails to update the value.  If it is unchecked and I set it to $True it remains unchecked.  If it is checked and I set it to $False it remains checked.  Same problem with -RunScriptAs32bitProcessOn64bitClient when doing manual detection script.
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2013 4:19pm

Hey,

are there any news on the "-scriptinstall" parameter? I know it can be done with WMI but the cmdlet would be much smarter? 

best regards

Philipp

August 28th, 2013 5:40am

It's still broken and has been submitted to MS as a bug.  If you're wanting to run wrapper or utility scripts, you can work around the bug by using an MSI deployment type and specifying your script names in -InstallationProgram and -UninstallProgram. Works fine and SCCM doesn't care if the source files contain an MSI or not.
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2013 12:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics