Update content on an application with Powershell or WMI in Microsoft SCMM 2012 SP1

8,824

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.

Share:
8,824

Related videos on Youtube

Chrizmo
Author by

Chrizmo

Updated on September 18, 2022

Comments

  • Chrizmo
    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
      gusya59 almost 11 years
      WMI 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
    Jason Sypkens over 10 years
    I'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
    Chrizmo over 10 years
    That's odd, does the application get a new version-ID in the UI?
  • Chrizmo
    Chrizmo over 10 years
    If 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
    Jason Sypkens over 10 years
    Response is "returnvalue: 0" (with a bunch of other WMI fluff to go with it). It is on SCCM 2012 SP1.