diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ce7871..f206162 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: name: Analyze & Test runs-on: windows-latest strategy: + fail-fast: false matrix: psversion: ['5.1', '7.4'] steps: diff --git a/Modules/Core/PrinterToolkit.Core.psm1 b/Modules/Core/PrinterToolkit.Core.psm1 index a6b84a5..86a0914 100644 --- a/Modules/Core/PrinterToolkit.Core.psm1 +++ b/Modules/Core/PrinterToolkit.Core.psm1 @@ -144,7 +144,11 @@ function Get-Printers { [CmdletBinding()] [OutputType([array])] param() - return @(Get-Printer -ErrorAction SilentlyContinue) + try { + return ,@(Get-Printer -ErrorAction SilentlyContinue) + } catch { + return ,@() + } } function Set-DefaultPrinter { diff --git a/Modules/Reporting/PrinterToolkit.Reporting.psm1 b/Modules/Reporting/PrinterToolkit.Reporting.psm1 index 48d882e..6fdc1b9 100644 --- a/Modules/Reporting/PrinterToolkit.Reporting.psm1 +++ b/Modules/Reporting/PrinterToolkit.Reporting.psm1 @@ -216,7 +216,11 @@ function Get-PrintComplianceReport { [CmdletBinding()] [OutputType([array])] param() - $printers = @(Get-Printer -ErrorAction SilentlyContinue) + try { + $printers = @(Get-Printer -ErrorAction SilentlyContinue) + } catch { + $printers = @() + } $drivers = @(Get-PrinterDriver -ErrorAction SilentlyContinue) $results = foreach ($p in $printers) { @@ -247,7 +251,7 @@ function Get-PrintComplianceReport { } } - return ,$results + return ,@($results) } Export-ModuleMember -Function New-PrinterReport, Get-PrintComplianceReport diff --git a/Modules/Sharing/PrinterToolkit.Sharing.psm1 b/Modules/Sharing/PrinterToolkit.Sharing.psm1 index 941e22a..efe16bb 100644 --- a/Modules/Sharing/PrinterToolkit.Sharing.psm1 +++ b/Modules/Sharing/PrinterToolkit.Sharing.psm1 @@ -16,7 +16,11 @@ function Get-PrinterShareStatus { [CmdletBinding()] [OutputType([array])] param() - $printers = @(Get-Printer -ErrorAction SilentlyContinue) + try { + $printers = @(Get-Printer -ErrorAction SilentlyContinue) + } catch { + $printers = @() + } $results = foreach ($p in $printers) { $driver = Get-PrinterDriver -Name $p.DriverName -ErrorAction SilentlyContinue $isIPP = if ($p.PortName -match '^(http|ipp|wsd|wsdprint)') { $true } else { $false } @@ -36,7 +40,7 @@ function Get-PrinterShareStatus { } } - return ,$results + return ,@($results) } function Enable-PrinterSharing { @@ -121,7 +125,7 @@ function Get-SmbSharePermissions { } } - return ,$results + return ,@($results) } function Set-PrinterSharePermission { @@ -230,7 +234,7 @@ function Get-PrinterSharingCompatibility { } } - return ,$results + return ,@($results) } Export-ModuleMember -Function Get-PrinterShareStatus, Enable-PrinterSharing, Disable-PrinterSharing, Get-SmbSharePermissions, Set-PrinterSharePermission, Set-PrinterSharingTransport, Get-PrinterSharingCompatibility diff --git a/Modules/Utilities/PrinterToolkit.Utilities.psm1 b/Modules/Utilities/PrinterToolkit.Utilities.psm1 index 759916e..04283ab 100644 --- a/Modules/Utilities/PrinterToolkit.Utilities.psm1 +++ b/Modules/Utilities/PrinterToolkit.Utilities.psm1 @@ -123,7 +123,7 @@ function Write-MenuHeader { [string]$Subtitle = '' ) - Clear-Host + try { Clear-Host } catch { } $line = '=' * 74 Write-Host $line -ForegroundColor Cyan Write-Host " $Title" -ForegroundColor White @@ -140,7 +140,7 @@ function Wait-Menu { param() Write-Host '' Write-Host 'Press any key to continue...' -ForegroundColor DarkGray - $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') + try { $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') } catch { } } Export-ModuleMember -Function Test-Administrator, Test-Elevated, Assert-Elevated, Confirm-DestructiveAction, Get-SystemInfo, Write-MenuHeader, Wait-Menu diff --git a/Tests/PrinterToolkit.Tests.ps1 b/Tests/PrinterToolkit.Tests.ps1 index c261015..ef802eb 100644 --- a/Tests/PrinterToolkit.Tests.ps1 +++ b/Tests/PrinterToolkit.Tests.ps1 @@ -97,7 +97,8 @@ Describe 'Core Module' { Describe 'Utilities Module' { It 'Test-Administrator should return boolean' { - Test-Administrator -is [bool] | Should -Be $true + $result = Test-Administrator + $result -is [bool] | Should -Be $true } It 'Test-Elevated calls Test-Administrator' { @@ -110,12 +111,12 @@ Describe 'Utilities Module' { } It 'Assert-Elevated should not throw when admin' { - Mock Test-Administrator { return $true } + Mock Test-Administrator { return $true } -ModuleName 'PrinterToolkit.Utilities' { Assert-Elevated } | Should -Not -Throw } It 'Assert-Elevated should throw when not admin' { - Mock Test-Administrator { return $false } + Mock Test-Administrator { return $false } -ModuleName 'PrinterToolkit.Utilities' { Assert-Elevated } | Should -Throw } }