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

PowerShell Basics: Variables

Variables are an integral part of how PowerShell works

Variables are a fundamental part of Windows PowerShell. They’re quite different from the variables in Cmd.exe. In Cmd.exe, all variables are environment variables, which you primarily access with the Set command. The environment variables can store only strings of text. (You can store a number in an environment variable, but it’s up to the program that’s reading the environment variable to interpret it as a number.)

The variables in PowerShell aren’t environment variables but rather native PowerShell variables. They can store much more than just text. In fact, PowerShell variables store objects (specifically, Microsoft .NET Framework objects). For example, a PowerShell variable can contain a String object or a number object, such as an Int (integer) object. Objects provide an extraordinary amount of flexibility.
Click here for more with examples

Also

Handy Configuration Manager 2012 powershell environment variables you should know