Skip to content

Commit e0f2ed1

Browse files
Fix Get-CatalogInfo and Booleans in Settings Files
1 parent 3af831d commit e0f2ed1

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

Invoke-DGASoftwareUpdateMaintenance/Invoke-DGASoftwareUpdateMaintenance.ps1

+44-22
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Version 2.4.6 12/19/2019
119119
Added catalog size information.
120120
Version 2.4.7 01/08/20
121121
The sync check will now check for multiple status messages to determine if the SUP is still syncing. (Charles - @NoRemoteUsers).
122+
Version 2.4.8 01/24/20
123+
Change Get-CatalogInfo function to make its own connection.
124+
Fix Boolean handling in settings file.
122125
[TODO] Sync approvals throughout hierarchy.
123126
[TODO] Orchestrate decline top-down and cleanup bottom-up throughout hierarchy.
124127
.LINK
@@ -867,14 +870,19 @@ Function Get-CatalogInfo{
867870
[OutputType([System.Data.DataTable])]
868871
Param(
869872
[Parameter(Mandatory=$true)]
870-
[System.Data.SqlClient.SqlConnection] $SqlConnection,
871-
[Parameter(Mandatory=$true)]
872-
[string] $SUSDbName,
873+
[Microsoft.UpdateServices.Administration.IDatabaseConfiguration] $WSUSServerDB,
873874
[string] $LogFile = "Get-CatalogInfo.log"
874875
)
875876

876-
$query = "
877-
Use $SUSDbName;
877+
$SqlConnection = Connect-WSUSDB $WSUSServerDB $LogFile
878+
879+
If(!$SqlConnection)
880+
{
881+
Add-TextToCMLog $LogFile "Failed to connect to the WSUS database '$($WSUSServerDB.ServerName)'." $component 1
882+
}
883+
else {
884+
$query =
885+
"Use $($WSUSServerDB.DatabaseName);
878886
;with cte as​
879887
(​
880888
SELECT dbo.tbXml.RevisionID, ISNULL(datalength(dbo.tbXml.RootElementXml), 0) as Uncompressed, ISNULL(datalength(dbo.tbXml.RootElementXmlCompressed), 0) as Compressed FROM dbo.tbXml​
@@ -896,15 +904,15 @@ Param(
896904
Inner Join tbBundleAtLeastOne t2​
897905
On t1.BundledID=t2.BundledID​
898906
Where ishidden=0 and pr.ExplicitlyDeployable=1​
899-
)
900-
"
907+
)"
901908

902-
return Invoke-SQLCMD $SqlConnection $query $LogFile
909+
return Invoke-SQLCMD $SqlConnection $query $LogFile
910+
}
903911
}
904912
#endregion
905913

906914
$cmSiteVersion = [version]"5.00.8540.1000"
907-
$scriptVersion = "2.4.7"
915+
$scriptVersion = "2.4.8"
908916
$component = 'Invoke-DGASoftwareUpdateMaintenance'
909917
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
910918
$IndexArray = @{
@@ -965,11 +973,11 @@ If ($ConfigFile){
965973
$Data[1]=$Data[1].Trim()
966974
}
967975
#Try to evaluate the value as an expression otherwise use the value as-is.
968-
Write-Verbose -Message "trying to Set Variable [$($Data[0])] to [$($Data[1])]"
976+
Write-Verbose -Message "trying to Set Variable [$($Data[0])] to [$($Data[1])]"
969977
Try{
970978
If ($Data[0] -eq 'SiteCode') { #force a numeric SiteCode to be a string
971979
Set-Variable -Name $Data[0] -Value ($Data[1] -as [string]) -Force -WhatIf:$False
972-
} ElseIf ($Data[1] -match "^@.") {
980+
} ElseIf ($Data[1] -match "^@." -or $Data[1] -match "$*") {
973981
Set-Variable -Name $Data[0] -Value (Invoke-Expression $Data[1]) -Force -WhatIf:$False
974982
} ElseIf ($Data[1] -match "^[0-9]*$") { #case where entire value is numeric
975983
Set-Variable -Name $Data[0] -Value ($Data[1] -as [int]) -Force -WhatIf:$False
@@ -1466,6 +1474,14 @@ $UpdatesToDecline = @{} #Hash table updates to decline.
14661474
$UpdatesToDelete = @{} #Hash table updates to delete.
14671475
If ($DeleteDeclined -or $DeclineSuperseded -or $DeclineByTitle -or $DeclineByPlugins){
14681476

1477+
$WSUSServerDB = Get-WSUSDB $WSUSServer $LogFile
1478+
If(!$WSUSServerDB)
1479+
{
1480+
Add-TextToCMLog $LogFile "Failed to get the WSUS database configuration." $component 3
1481+
Set-Location $OriginalLocation
1482+
Return
1483+
}
1484+
14691485
#Check the sync status.
14701486
If ($StandAloneWSUS){
14711487
Invoke-WSUSSyncCheck $WSUSServer $LogFile
@@ -1508,12 +1524,15 @@ If ($DeleteDeclined -or $DeclineSuperseded -or $DeclineByTitle -or $DeclineByPlu
15081524
$ActiveUpdates = $AllUpdates | Where-Object {$_.IsDeclined -eq $False}
15091525

15101526
#Estimate catalog size
1511-
$CatalogInfo = Get-CatalogInfo $SqlConnection $($WSUSServerDB.DatabaseName) $LogFile
1512-
$InitialCatlogSize="Unknown"
1513-
$InitialCatlogSizeCompressed="Unknown"
1514-
If($CatalogInfo.Rows.Count -gt 0 ){
1515-
$InitialCatlogSize=$CatalogInfo.Rows[0].CatalogSize_MB
1516-
$InitialCatlogSizeCompressed=$CatalogInfo.Rows[0].CompressedCatalogSize_MB
1527+
if ($WSUSServerDB)
1528+
{
1529+
$CatalogInfo = Get-CatalogInfo $WSUSServerDB $LogFile
1530+
$InitialCatlogSize="Unknown"
1531+
$InitialCatlogSizeCompressed="Unknown"
1532+
If($CatalogInfo.Rows.Count -gt 0 ){
1533+
$InitialCatlogSize=$CatalogInfo.Rows[0].CatalogSize_MB
1534+
$InitialCatlogSizeCompressed=$CatalogInfo.Rows[0].CompressedCatalogSize_MB
1535+
}
15171536
}
15181537

15191538
#Initialize count variables.
@@ -1775,10 +1794,13 @@ If ($DeleteDeclined -or $DeclineSuperseded -or $DeclineByTitle -or $DeclineByPlu
17751794
}
17761795

17771796
#Restimate catalog size
1778-
$NewCatalogInfo = Get-CatalogInfo $SqlConnection $($WSUSServerDB.DatabaseName) $LogFile
1779-
If($NewCatalogInfo.Rows.Count -gt 0 ){
1780-
$InitialCatlogSize=$NewCatalogInfo.Rows[0].CatalogSize_MB
1781-
$InitialCatlogSizeCompressed=$NewCatalogInfo.Rows[0].CompressedCatalogSize_MB
1797+
if ($WSUSServerDB)
1798+
{
1799+
$NewCatalogInfo = Get-CatalogInfo $WSUSServerDB $LogFile
1800+
If($NewCatalogInfo.Rows.Count -gt 0 ){
1801+
$InitialCatlogSize=$NewCatalogInfo.Rows[0].CatalogSize_MB
1802+
$InitialCatlogSizeCompressed=$NewCatalogInfo.Rows[0].CompressedCatalogSize_MB
1803+
}
17821804
}
17831805

17841806
#Write the summary information.
@@ -1814,7 +1836,7 @@ If ($DeleteDeclined -or $DeclineSuperseded -or $DeclineByTitle -or $DeclineByPlu
18141836
Add-TextToCMLog $LogFile "Total Active Updates = $($AllUpdates.Count - $DeclinedUpdates.Count - $countNewlyDeclined)" $component 1
18151837
Add-TextToCMLog $LogFile "Total Updates = $($AllUpdates.Count - $countNewlyDeleted)" $component 1
18161838
If($NewCatalogInfo.Rows.Count -gt 0 ){
1817-
Add-TextToCMLog $LogFile "Initial Catalog Size = $($NewCatalogInfo.Rows[0].CatalogSize_MB) MB ($($NewCatalogInfo.Rows[0].CompressedCatalogSize_MB) MB Compressed )" $component 1
1839+
Add-TextToCMLog $LogFile "New Catalog Size = $($NewCatalogInfo.Rows[0].CatalogSize_MB) MB ($($NewCatalogInfo.Rows[0].CompressedCatalogSize_MB) MB Compressed )" $component 1
18181840
}
18191841
Add-TextToCMLog $LogFile "========" $component 1
18201842

0 commit comments

Comments
 (0)