Update content on an application with Powershell or WMI in Microsoft SCMM 2012 SP1
Solution 1
After some intense searching I found a solution. In the SCCM SDK there's a WMI class called SMS_ContentPackage, which has the public method Commit(). Using this I was able to update content on all applications, using the following Powershell-code on the server:
foreach($application in Get-CMApplication){
$Get_WmiObject = @{
'Namespace' = 'root\SMS\Site_<SiteCode>';
'Class' = 'SMS_ContentPackage';
'Filter' = "PackageID='$($application.PackageId)'";
}
(Get-Wmiobject @Get_WmiObject).Commit() | Out-null
}
Solution 2
I'm currently using this powershell script to update the content of all applications, only caveat is, the revision always gets increased:
try
{
Get-Wmiobject -Namespace "root\SMS\Site_<sitecode>" -Class SMS_Application -Filter "isLatest='true' and isExpired='false'" | foreach{
$name = $_.LocalizedDisplayName
echo "Application : $name"
$dptypes = Get-CMDeploymentType -ApplicationName "$name"
foreach ($dpt in $dptypes){
$dptname = $dpt.LocalizedDisplayName
echo "Deployment Type: $dptname"
Update-CMDistributionPoint -ApplicationName "$name" -DeploymentTypeName "$dptname"
}
}
}
catch
{
$_.Exception.Message
}
Solution 3
Set-CMDeploymentType with -ContentLocation will force an update, even if the ContentLocation is set to the same as the original.
My code looks like this:
$app = Get-CMApplication -Name $PackageName
$depType = $app | Get-CMDeploymentType
$depType | Set-CMDeploymentType -MsiOrScriptInstaller -ProductCode $productCode -ContentLocation $PkgRead
The existing location can be trickier to determine - if you don't already know where it is, you can pull it out of the deployment type XML or WMI.
Related videos on Youtube
Chrizmo
Updated on September 18, 2022Comments
-
Chrizmo over 1 year
While right-clicking an applications deployment type(s), we can select Update Content. Is there a way of doing this action using Powershell or a WMI-method?
-
gusya59 almost 11 yearsWMI is to pull information from the system. I don't know the powershell option, however why not schedule this installed under the data source of the application to update the distribution points?
-
-
Jason Sypkens over 10 yearsI'm trying to accomplish this as well, and your answer doesn't appear to be working for me. I am able to run the commit method, but it doesn't update the package. When running Get-CMApplication, I see that the SDMPackageVersion does not change, and the SDMPackageXML still reflects the old content. When I hit "Update Content" through the SCCM console, those values are updated to reflect the new content.
-
Chrizmo over 10 yearsThat's odd, does the application get a new version-ID in the UI?
-
Chrizmo over 10 yearsIf you ommit piping the output to Out-Null, do you get a response? Also, I don't know if it matters, but this was done on SCCM 2012 SP1, are you using that as well?
-
Jason Sypkens over 10 yearsResponse is "returnvalue: 0" (with a bunch of other WMI fluff to go with it). It is on SCCM 2012 SP1.