Powershell script to compare DP packages with WMI

http://blogs.technet.com/b/configmgrteam/archive/2012/05/07/troubleshooting-content-mismatch-warnings-on-a-distribution-point-in-system-center-2012-configuration-manager.aspx

Blog on the content library

Blog on troubleshooting content 2012

$WMIPkgList = Get-WmiObject -Namespace Root\SCCMDP -Class SMS_PackagesInContLib | Select -ExpandProperty PackageID | Sort-Object

$ContentLib = (Get-ItemProperty -path HKLM:SOFTWARE\Microsoft\SMS\DP -Name ContentLibraryPath)

$PkgLibPath = ($ContentLib.ContentLibraryPath) + “\PkgLib”

$PkgLibList = (Get-ChildItem $PkgLibPath | Select -ExpandProperty Name | Sort-Object)

$PkgLibList = ($PKgLibList | ForEach-Object {$_.replace(“.INI”,””)})

$PksinWMIButNotContentLib = Compare-Object -ReferenceObject $WMIPkgList -DifferenceObject $PKgLibList -PassThru | Where-Object { $_.SideIndicator -eq “” }

Write-Host Items in WMI but not the Content Library
Write-Host ========================================
$PksinWMIButNotContentLib

Write-Host Items in Content Library but not WMI
Write-Host ====================================
$PksinContentLibButNotWMI

To remove the item from WMI (Using the list from the previous script):
Foreach ($Pkg in $PksinWMIButNotContentLib){
Get-WmiObject -Namespace Root\SCCMDP -Class SMS_PackagesInContLib -Filter “PackageID = ‘$Pkg'” | Remove-WmiObject -Confirm
}

To remove INI files using the list from the previous script:
Foreach ($Pkg in $PksinContentLibButNotWMI){
Remove-Item -Path “$PkgLibPath\$Pkg.INI” -Confirm
}

Advertisements

2 thoughts on “Powershell script to compare DP packages with WMI

  1. Hi, I couldn’t get your script to work correctly so I made some changes. But your post got me on the right way 🙂

    $WMIPkgList = Get-WmiObject -Namespace Root\SCCMDP -Class SMS_PackagesInContLib | Select -ExpandProperty PackageID | Sort-Object

    $ContentLib = (Get-ItemProperty HKLM:SOFTWARE\Microsoft\SMS\DP).ContentLibraryPath

    $PkgLibPath = ($ContentLib) + ‘\PkgLib’

    $PkgLibList = (Get-ChildItem $PkgLibPath | Select -ExpandProperty Name | Sort-Object)

    $PkgLibList = ($PKgLibList | ForEach-Object {$_.replace(‘.INI’,”)})

    $PksinWMIButNotContentLib = Compare-Object -ReferenceObject $WMIPkgList -DifferenceObject $PKgLibList -PassThru | Where-Object { $_.SideIndicator -eq ” }

    Write-Host Items in WMI but not the Content Library
    Write-Host ========================================
    $PksinWMIButNotContentLib

    Write-Host Items in Content Library but not WMI
    Write-Host ====================================
    $PksinContentLibButNotWMI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s