Skip to content

Commit 0b9d5e4

Browse files
author
Fedor Ershov
committed
Merge branch 'dev' into 'master'
Release v.2.9.1 See merge request fozzy-winadmins/AutomaticMaintenance!18
2 parents 5d74cc9 + 982bc9e commit 0b9d5e4

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

AutomaticMaintenance.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'AutomaticMaintenance.psm1'
3-
ModuleVersion = '2.9'
3+
ModuleVersion = '2.9.1'
44
GUID = '8e34abf8-40ba-4c68-8bf8-f235cd001d82'
55
Author = 'Kirill Nikolaev'
66
CompanyName = 'Fozzy Inc.'
@@ -26,6 +26,6 @@
2626
LicenseUri = 'https://github.com/FozzyHosting/AutomaticMaintenance/blob/master/LICENSE'
2727
ProjectUri = 'https://github.com/FozzyHosting/AutomaticMaintenance/'
2828
ReleaseNotes = ''
29-
}
29+
}
3030
}
3131
}

AutomaticMaintenance.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $ModuleName = ($MyInvocation.MyCommand.Name).Substring(0, ($MyInvocation.MyComma
2929
[System.TimeSpan]$ModuleWidePreventiveLockThreshold = New-Object -TypeName 'System.TimeSpan' -ArgumentList @(1, 0, 0)
3030
[bool]$ModuleWideSkipPreventivelyLocked = $true
3131
[bool]$ModuleWideSkipNotLockable = $true
32+
[string]$ModuleWideSkipPreventivelyLockedFullyQualifiedErrorId = 'SkipPreventivelyLockedHost'
3233

3334
[int]$ModuleWideInstallUpdateTimeout = 60
3435
[System.TimeSpan]$ModuleWideInstallUpdateThreshold = New-Object -TypeName 'System.TimeSpan' -ArgumentList @(1, 0, 0)

Private/Initialize-ComputerMaintenance.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function Initialize-ComputerMaintenance {
88
[Parameter(Mandatory)]
99
[ref]$DestinationHostLock,
1010
[switch]$SkipNotLockable,
11-
[switch]$SkipPreventivelyLocked
11+
[switch]$SkipPreventivelyLocked,
12+
[string]$SkipPreventivelyLockedFullyQualifiedErrorId
1213
)
1314

1415
$ErrorActionPreference = 'Stop'
@@ -75,8 +76,8 @@ function Initialize-ComputerMaintenance {
7576
Write-Debug -Message ('$SkipPreventivelyLocked: ''{0}''' -f $SkipPreventivelyLocked)
7677
Write-Debug -Message 'if ($SkipPreventivelyLocked)'
7778
if ($SkipPreventivelyLocked) {
78-
Write-Debug -Message 'return'
79-
return
79+
$Message = ('Skipping the computer {0} because it is locked by other sources for more than {1} already and $SkipPreventivelyLocked is {2}.' -f $ComputerName, [string]$PreventiveLockThreshold, [string]$SkipPreventivelyLocked)
80+
$PSCmdlet.ThrowTerminatingError((New-Object -TypeName 'System.Management.Automation.ErrorRecord' -ArgumentList ((New-Object -TypeName 'System.OperationCanceledException' -ArgumentList $Message), $SkipPreventivelyLockedFullyQualifiedErrorId, [System.Management.Automation.ErrorCategory]::OperationStopped, $null)))
8081
}
8182
else {
8283
$Message = ('Computer {0} is locked by other sources for more than {1} already' -f $ComputerName, [string]$PreventiveLockThreshold)

Public/Invoke-ComputerMaintenance.ps1

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function Invoke-ComputerMaintenance {
66
[string]$ComputerName,
77
[int]$PreventiveLockTimeout = $ModuleWidePreventiveLockTimeout,
88
[System.TimeSpan]$PreventiveLockThreshold = $ModuleWidePreventiveLockThreshold,
9+
[string]$SkipPreventivelyLockedFullyQualifiedErrorId = $ModuleWideSkipPreventivelyLockedFullyQualifiedErrorId,
910
[switch]$SkipNotLockable = $ModuleWideSkipNotLockable,
1011
[switch]$SkipPreventivelyLocked = $ModuleWideSkipPreventivelyLocked,
1112
[switch]$EnableMaintenanceLog = $ModuleWideEnableMaintenanceLog
@@ -44,8 +45,8 @@ function Invoke-ComputerMaintenance {
4445
Write-Debug -Message 'if ($PendingReboot.ComponentBasedServicing)'
4546
if ($PendingReboot.ComponentBasedServicing) {
4647
# Sometimes, when CBS requires reboot, search for updates hangs up. Therefore, we need to reboot the machine first.
47-
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2}' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked)
48-
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked
48+
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2} -SkipPreventivelyLockedFullyQualifiedErrorId ''{3}''' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked, $SkipPreventivelyLockedFullyQualifiedErrorId)
49+
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked -SkipPreventivelyLockedFullyQualifiedErrorId $SkipPreventivelyLockedFullyQualifiedErrorId
4950
Write-Debug -Message ('$ComputerWorkload: ''{0}''' -f [string]$ComputerWorkload)
5051

5152
Write-Debug -Message ('$HostLock: ''{0}''' -f $HostLock)
@@ -72,8 +73,8 @@ function Invoke-ComputerMaintenance {
7273
$IsMaintenanceNeeded = Test-MaintenanceNeeded -ComputerName $ComputerName
7374
Write-Debug -Message ('$IsMaintenanceNeeded = ${0}' -f $IsMaintenanceNeeded)
7475
if ($IsMaintenanceNeeded) {
75-
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2}' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked)
76-
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked
76+
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2} -SkipPreventivelyLockedFullyQualifiedErrorId ''{3}''' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked, $SkipPreventivelyLockedFullyQualifiedErrorId)
77+
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked -SkipPreventivelyLockedFullyQualifiedErrorId $SkipPreventivelyLockedFullyQualifiedErrorId
7778
Write-Debug -Message ('$ComputerWorkload: ''{0}''' -f [string]$ComputerWorkload)
7879
Write-Debug -Message ('$HostLock: ''{0}''' -f $HostLock)
7980
Write-Debug -Message 'if ($HostLock)'
@@ -90,8 +91,8 @@ function Invoke-ComputerMaintenance {
9091
# If the machine does not need any updates, but just a reboot, let's reboot it.
9192
Write-Debug -Message ('$PendingReboot.IsRebootPending: ''{0}''' -f $PendingReboot.IsRebootPending)
9293
if ($PendingReboot.IsRebootPending) {
93-
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2}' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked)
94-
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked
94+
Write-Debug -Message ('$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName ''{0}'' -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:${1} -SkipPreventivelyLocked:${2} -SkipPreventivelyLockedFullyQualifiedErrorId ''{3}''' -f $ComputerName, $SkipNotLockable, $SkipPreventivelyLocked, $SkipPreventivelyLockedFullyQualifiedErrorId)
95+
$ComputerWorkload = Initialize-ComputerMaintenance -ComputerName $ComputerName -HostLock ([ref]$HostLock) -DestinationHostLock ([ref]$DestinationHostLock) -SkipNotLockable:$SkipNotLockable -SkipPreventivelyLocked:$SkipPreventivelyLocked -SkipPreventivelyLockedFullyQualifiedErrorId $SkipPreventivelyLockedFullyQualifiedErrorId
9596
Write-Debug -Message ('$ComputerWorkload: ''{0}''' -f [string]$ComputerWorkload)
9697
Write-Debug -Message ('$HostLock: ''{0}''' -f $HostLock)
9798
Write-Debug -Message 'if ($HostLock)'
@@ -113,8 +114,13 @@ function Invoke-ComputerMaintenance {
113114
catch {
114115
Write-Debug -Message ('ENTER CATCH {0}' -f $MyInvocation.MyCommand.Name)
115116

116-
Write-Debug -Message ('{0}: $PSCmdlet.ThrowTerminatingError($_)' -f $MyInvocation.MyCommand.Name)
117-
$PSCmdlet.ThrowTerminatingError($_)
117+
Write-Debug -Message ('$_.FullyQualifiedErrorId: ''{0}''' -f $_.FullyQualifiedErrorId)
118+
Write-Debug -Message ('if ($_.FullyQualifiedErrorId -ne ''{0}'')' -f $SkipPreventivelyLockedFullyQualifiedErrorId)
119+
if ($_.FullyQualifiedErrorId -ne $SkipPreventivelyLockedFullyQualifiedErrorId) {
120+
121+
Write-Debug -Message ('{0}: $PSCmdlet.ThrowTerminatingError($_)' -f $MyInvocation.MyCommand.Name)
122+
$PSCmdlet.ThrowTerminatingError($_)
123+
}
118124

119125
Write-Debug -Message ('EXIT CATCH {0}' -f $MyInvocation.MyCommand.Name)
120126
}

0 commit comments

Comments
 (0)