to create an SCCM application deployment with powershell you have to be patient, because the error output from the server is always “generic failiure”..
and there is not much help to get from Microsofts SMS_CIAssignmentBaseClass specification.
BUT! I had luck. A dude called Rob Looman already had most of the work published on his site. Thanks Rob 🙂
It took me a while to figure out how to make the specific deployments to be created properly because mandatory uninstalls didn’t work with Robs script.
But here it is, I hope it will save you some time!
function Create-ApplicationDeployment
{
param
(
[Parameter(Mandatory=$True, HelpMessage="The name of the SCCM site server")]
$SCCMsiteServer,
[Parameter(Mandatory=$True, HelpMessage="The name of the sitecode")]
$SCCMsiteCode,
[Parameter(Mandatory=$True, HelpMessage="The name you wish of the deployment")]
$AssignName,
[Parameter(Mandatory=$True, HelpMessage="The name of the application to run")]
$AppName,
[Parameter(Mandatory=$True, HelpMessage="The application ID of the application to run ")]
$AppID,
[Parameter(Mandatory=$True, HelpMessage="The name of the collection to target")]
$CollName,
[Parameter(Mandatory=$True, HelpMessage="The collection ID of the target collection")]
$CollID,
[Parameter(Mandatory=$True, HelpMessage="The offertype of the deployment. 2 = Available, 0 = Required")]
$OfferType,
[Parameter(Mandatory=$True, HelpMessage="The action the application should perform. 1 = Install, 2= Uninstall")]
$ConfType
)
try
{
$newApplicationAssingment = ([wmiclass]("\\$SCCMsiteServer\ROOT\sms\site_" + $SCCMsiteCode + ":SMS_ApplicationAssignment")).CreateInstance()
$newApplicationAssingment.ApplicationName = $AppName
$newApplicationAssingment.AssignmentName = $AssignName
$newApplicationAssingment.AssignedCIs = $AppID
$newApplicationAssingment.CollectionName = $CollName
$newApplicationAssingment.LocaleID = 1033
$newApplicationAssingment.SourceSite = $SiteCode
$Format = get-date -format yyyyMMddHHmmss
$Date = $Format + ".000000+***"
$newApplicationAssingment.StartTime = $Date
$newApplicationAssingment.CreationTime = $Date
#This is only required on "Required" action deployments and will make an error if applied to available deployments
if ($OfferType -eq 0)
{
$newApplicationAssingment.EnforcementDeadline = $Date
}
$newApplicationAssingment.SuppressReboot = 0
$newApplicationAssingment.NotifyUser = $True
$newApplicationAssingment.TargetCollectionID = $CollID
$newApplicationAssingment.OfferTypeID = $OfferType # 2 = Available, 0 = DO IT!
$newApplicationAssingment.DesiredConfigType = $ConfType
$newApplicationAssingment.WoLEnabled = $false
$newApplicationAssingment.RebootOutsideOfServiceWindows = $false
$newApplicationAssingment.OverrideServiceWindows = $false
$newApplicationAssingment.UseGMTTimes = $true
$newApplicationAssingment.put()
}
catch
{
Write-Host "Error creating deployment: $_"
}
}
An example of a deployment that needs to be available and not force install:
Create-ApplicationDeployment -SCCMsiteServer "mroenborg.com" -SiteCode "_20" -AssignName "Adobe Reader - (Avi Inst)" -AppName "Adobe Reader 15.0.0" -AppID "A0001212" -CollName "All users" -CollID "P0000001" -OfferType 2 -ConfType 1
An example of a deployment that requires an install:
Create-ApplicationDeployment -SCCMsiteServer "mroenborg.com" -SiteCode "_20" -AssignName "Adobe Reader - (Inst)" -AppName "Adobe Reader 15.0.0" -AppID "A0001212" -CollName "All users" -CollID "P0000001" -OfferType 0 -ConfType 1
An example of a deployment that requires an uninstall:
Create-ApplicationDeployment -SCCMsiteServer "mroenborg.com" -SiteCode "_20" -AssignName "Adobe Reader - (Uninst)" -AppName "Adobe Reader 15.0.0" -AppID "A0001212" -CollName "All users" -CollID "P0000001" -OfferType 0 -ConfType 2
There it is guys..
As always don’t hesitate to ask in the comment section!
Thanks
Hi,
I am getting below error while executing the script. Please let me know what i am missing
Error creating deployment: Cannot convert value “\\XXXX.XXX.XX\ROOT\sms\site_XXX:SMS_ApplicationAssignment” to type “System.
Management.ManagementClass”. Error: “Invalid namespace “
Hi Karthik
I just tested the script on my test environment, and it works fine. Are you able to list all applications with this query:
Get-WMIobject -ComputerName SITESERVER -Namespace “root\sms\site_SITECODE” -query “select * from SMS_Application”
Are you running this from the server or a client?
Kind regards
Morten
I know this is old, but it is still relevant, so figured I as the question…on all above should it be assignment or assingment?
“$newApplicationAssingment.OfferTypeID”
Regis High School