Last active
March 7, 2025 17:18
-
-
Save MyITGuy/3f906e5b1d57bbd12d5cf5fff5a8ac48 to your computer and use it in GitHub Desktop.
This script repairs the "The package data in WMI is not consistent to PkgLib" and "Package can't be found in PkgLib" errors in smsdpmon.log on Distribution Points by
searching for packages that appear to be in de Content Library according to WMI but
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Repairs the "The package data in WMI is not consistent to PkgLib" errors after ConfigMgr2012R2 upgrade | |
.DESCRIPTION | |
This script repairs the "The package data in WMI is not consistent to PkgLib" errors after ConfigMgr2012R2 upgrade by | |
searching for packages that appear to be in de Content Library according to WMI but are not there and do not exist anymore | |
This cleanup will run against all distribution points and when invalid WMI instances are found, they will be removed. | |
Detailed description of this issue: 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?wa=wsignin1.0 | |
Script is to be used at own risk | |
.EXAMPLE | |
Remove-WMIInvalidContent.ps1 -Siteserver myserver.mydomain.com -Sitecode AAA | |
.LINK | |
http://gallery.technet.microsoft.com/Powershell-script-to-fix-81dc4e69 | |
.NOTES | |
Written by Bart Serneels | |
Assisted by Stijn Callebaut | |
#> | |
param( | |
[parameter(Mandatory = $true)] | |
[string]$SiteServer, | |
[parameter(Mandatory = $true)] | |
[string]$SiteCode | |
) | |
$Namespace = "root\SMS\Site_" + $SiteCode | |
Write-Host "Getting all valid packages... " -NoNewline | |
$ValidPackages = Get-WMIObject -ComputerName $SiteServer -Namespace $Namespace -Query "Select * from SMS_ObjectContentExtraInfo" | |
Write-Host ([string]($ValidPackages.count) + " packages found.") | |
Write-Host "Getting all valid distribution points... " -NoNewline | |
$DistributionPoints = Get-WMIObject -ComputerName $SiteServer -Namespace $Namespace -Query "select * from SMS_DistributionPointInfo where ResourceType = 'Windows NT Server'" | |
Write-Host ([string]($DistributionPoints.count) + " distribution points found.") | |
Write-Host "" | |
foreach ($DistributionPoint in $DistributionPoints) { | |
$InvalidPackages = @() | |
$DistributionPointName = $DistributionPoint.ServerName | |
if ( -not(Test-Connection $DistributionPointName -Quiet -Count 1)) { | |
Write-error "Could not connect to DistributionPoint $DistributionPointName - Skipping this server..." | |
} | |
else { | |
Write-Host "$DistributionPointName is online." -ForegroundColor Green | |
Write-Host "Getting packages from $DistributionPointName ... " -NoNewline | |
$CurrentPackageList = @(Get-WMIObject -ComputerName $DistributionPointName -Namespace "root\sccmdp" -Query "Select * from SMS_PackagesInContLib") | |
Write-Host ([string]($CurrentPackageList.Count) + " packages found.") | |
if (($CurrentPackageList.Count -eq 0) -or ($CurrentPackageList -eq $null)){ | |
Write-Host "Skipping this distribution point" | |
} | |
else{ | |
Write-Host "Validating packages on $DistributionPointName ..." | |
$result = @(Compare-Object -ReferenceObject $CurrentPackageList -DifferenceObject $ValidPackages -Property PackageID -PassThru) | |
$InvalidPackages = @($result |Where-Object {$_.sideindicator -eq '<='}) | |
if ($InvalidPackages.Count -eq 0){ | |
Write-Host "All packages on $DistributionPointName are valid" -ForegroundColor Green | |
} | |
Else { | |
Write-Host "Invalid packages on $DistributionPointName :" -ForegroundColor Yellow | |
$InvalidPackages.PackageID | |
$InvalidPackages | foreach { | |
$InvalidPackageID = $_.PackageID | |
Write-Host "Removing invalid package $InvalidPackageID from WMI on $DistributionPointName " -NoNewline | |
Get-WMIObject -ComputerName $DistributionPointName -Namespace "root\sccmdp" -Query ("Select * from SMS_PackagesInContLib where PackageID = '" + ([string]($_.PackageID)) + "'") | Remove-WmiObject | |
Write-Host "-Done" | |
} | |
} | |
Write-Host "" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-WMIInvalidContent { | |
<# | |
.SYNOPSIS | |
Repairs the "The package data in WMI is not consistent to PkgLib" errors after ConfigMgr2012R2 upgrade | |
.DESCRIPTION | |
This script repairs the "The package data in WMI is not consistent to PkgLib" errors after ConfigMgr2012R2 upgrade by | |
searching for packages that appear to be in de Content Library according to WMI but are not there and do not exist anymore | |
This cleanup will run against all distribution points and when invalid WMI instances are found, they will be removed. | |
Detailed description of this issue: 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?wa=wsignin1.0 | |
Script is to be used at own risk | |
.EXAMPLE | |
Remove-WMIInvalidContent.ps1 -Siteserver myserver.mydomain.com -Sitecode AAA | |
.LINK | |
http://gallery.technet.microsoft.com/Powershell-script-to-fix-81dc4e69 | |
.NOTES | |
Written by Bart Serneels | |
Assisted by Stijn Callebaut | |
Modified by Steven McCarty | |
- [Modified] General syntax updates | |
- [Modified] SiteServer parameter will default to using value from WMI | |
- [Modified] SiteCode parameter will default to using value from WMI | |
- [Added] CleanupInvalid parameter added so the code will only audit by default | |
- [Modified] Change WMI calls from WMI to CIM | |
#> | |
param( | |
[parameter(Mandatory = $false)] | |
[string]$SiteServer = (Get-CimInstance -ClassName SMS_Authority -Namespace root\ccm).CurrentManagementPoint | |
, | |
[parameter(Mandatory = $false)] | |
[string]$SiteCode = (Get-CimInstance -ClassName SMS_Authority -Namespace root\ccm).Name.Split(':')[1] | |
, | |
[parameter(Mandatory = $false)] | |
[string[]]$ComputerName | |
, | |
[parameter(Mandatory = $false)] | |
[switch]$CleanupInvalid | |
) | |
function Test-NetConnectionWithoutProgressBar ([string]$ComputerName) { | |
$global:ProgressPreference = 'SilentlyContinue' | |
$NetConnection = Test-NetConnection -ComputerName $ComputerName -Port 5985 -WarningAction SilentlyContinue | |
$global:ProgressPreference = 'Continue' | |
$NetConnection.TcpTestSucceeded | |
} | |
Write-Host "Using $($SiteServer) site server" | |
Write-Host "Using $($SiteCode) site code" | |
Write-Host "Limiting to the following computers: $($ComputerName -join ', ')" | |
Write-Host "Fix parameter is set to $($CleanupInvalid.IsPresent)." | |
Write-Host "" | |
$Namespace = "root\SMS\Site_$($SiteCode)" | |
Write-Host "Using $($Namespace) namespace" | |
Write-Host "Getting all valid packages from $($SiteServer) ... " -NoNewline | |
$SSValidPackages = Get-CimInstance -ComputerName $SiteServer -Namespace $Namespace -Query "Select * from SMS_ObjectContentExtraInfo" | |
Write-Host "$(($SSValidPackages | Measure-Object).Count) found" | |
Write-Host "Getting all valid distribution points from $($SiteServer) for site $($SiteCode) ... " -NoNewline | |
$DistributionPoints = Get-CimInstance -ComputerName $SiteServer -Namespace $Namespace -Query "select * from SMS_DistributionPointInfo where ResourceType = 'Windows NT Server'" | Sort-Object -Property ServerName | |
if ($ComputerName) { | |
$DistributionPoints = $DistributionPoints | Where-Object ServerName -in @($ComputerName) | |
} | |
Write-Host "$(($DistributionPoints | Measure-Object).Count) found" | |
Write-Host "" | |
foreach ($DistributionPoint in $DistributionPoints) { | |
$InvalidPackages = @() | |
$DistributionPointName = $DistributionPoint.ServerName | |
Write-Host "$DistributionPointName is " -NoNewline | |
if ( -not (Test-NetConnectionWithoutProgressBar -ComputerName $DistributionPointName )) { | |
Write-Host "INACCESSIBLE" -ForegroundColor Red -NoNewline | |
Write-Host " - Skipping this server." | |
} | |
else { | |
Write-Host "ACCESSIBLE" -ForegroundColor Green | |
Write-Host "Getting packages " -NoNewline | |
$DPCurrentPackageList = @(Get-CimInstance -ComputerName $DistributionPointName -Namespace "root\sccmdp" -Query "Select * from SMS_PackagesInContLib") | |
$DPTotalPackageCount = $DPCurrentPackageList | Measure-Object | Select-Object -ExpandProperty Count | |
Write-Host "(total: $($DPTotalPackageCount))" | |
if ($DPTotalPackageCount -eq 0) { | |
Write-Host "Skipping this distribution point" | |
} else { | |
Write-Host "Validating packages " -NoNewline | |
$DPResult = @(Compare-Object -ReferenceObject $DPCurrentPackageList -DifferenceObject $SSValidPackages -Property PackageID -IncludeEqual -PassThru) | Sort-Object -Property PackageID | |
$DPValidPackages = @($DPResult | Where-Object { $_.SideIndicator -eq '==' }) | |
$DPMissingPackages = @($DPResult | Where-Object { $_.SideIndicator -eq '=>' }) | |
$DPInvalidPackages = @($DPResult | Where-Object { $_.SideIndicator -eq '<=' }) | |
$DPValidPackageCount = $DPValidPackages | Measure-Object | Select-Object -ExpandProperty Count | |
Write-Host "(valid: $($DPValidPackageCount)" -NoNewline | |
$DPMissingPackageCount = $DPMissingPackages | Measure-Object | Select-Object -ExpandProperty Count | |
Write-Host ", missing: $($DPMissingPackageCount)" -NoNewline | |
$DPInvalidPackageCount = $DPInvalidPackages | Measure-Object | Select-Object -ExpandProperty Count | |
Write-Host ", invalid: $($DPInvalidPackageCount))" -NoNewline | |
Write-Host | |
if ($DPMissingPackageCount -ne 0) { | |
# Write-Host "Missing packages on $DistributionPointName : $($DPMissingPackages.PackageID -join ', ')" -ForegroundColor Yellow | |
foreach ($DPMissingPackage In $DPMissingPackages) { | |
$DPMissingPackageID = $DPMissingPackage.PackageID | |
# Write-Host "Missing package $DPMissingPackageID from WMI on $DistributionPointName" -ForegroundColor Yellow | |
} | |
} | |
if ($DPInvalidPackageCount -eq 0) { | |
Write-Host "No invalid packages on $DistributionPointName" -ForegroundColor Green | |
} else { | |
Write-Host "Invalid packages on $DistributionPointName : $($DPInvalidPackages.PackageID -join ', ')" -ForegroundColor Yellow | |
$DPInvalidPackages | ForEach-Object { | |
$DPInvalidPackageID = $_.PackageID | |
if ($CleanupInvalid.IsPresent -eq $true) { | |
Write-Host "Removal of invalid package $DPInvalidPackageID from WMI on $DistributionPointName was " -NoNewline | |
try { | |
Get-CimInstance -ComputerName $DistributionPointName -Namespace "root\sccmdp" -Query ("Select * from SMS_PackagesInContLib where PackageID = '$($DPInvalidPackageID)'") | Remove-CimInstance | |
Start-Sleep -Seconds 1 | |
} finally { | |
$CleanupCount = Get-CimInstance -ComputerName $DistributionPointName -Namespace "root\sccmdp" -Query ("Select * from SMS_PackagesInContLib where PackageID = '$($DPInvalidPackageID)'") | Measure-Object | Select-Object -ExpandProperty Count | |
if ($CleanupCount -ne 0) { | |
Write-Host "UNSUCCESSFUL" -ForegroundColor Red | |
} else { | |
Write-Host "SUCCESSFUL" -ForegroundColor Green | |
} | |
} | |
} | |
else { | |
Write-Host "Invalid package $DPInvalidPackageID will be removed from WMI on $DistributionPointName" | |
} | |
} | |
} | |
} | |
} | |
Write-Host "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment