mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
null-safe patches
This commit is contained in:
@@ -25,20 +25,35 @@ function Invoke-WinUtilScript {
|
||||
Invoke-Command $scriptblock -ErrorAction Stop
|
||||
} catch [System.Management.Automation.CommandNotFoundException] {
|
||||
Write-Warning "The specified command was not found."
|
||||
Write-Warning $PSItem.Exception.message
|
||||
if ($_.Exception -and -not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
} catch [System.Management.Automation.RuntimeException] {
|
||||
Write-Warning "A runtime exception occurred."
|
||||
Write-Warning $PSItem.Exception.message
|
||||
if ($_.Exception -and -not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
} catch [System.Security.SecurityException] {
|
||||
Write-Warning "A security exception occurred."
|
||||
Write-Warning $PSItem.Exception.message
|
||||
if ($_.Exception -and -not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
} catch [System.UnauthorizedAccessException] {
|
||||
Write-Warning "Access denied. You do not have permission to perform this operation."
|
||||
Write-Warning $PSItem.Exception.message
|
||||
if ($_.Exception -and -not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
} catch {
|
||||
# Generic catch block to handle any other type of exception
|
||||
Write-Warning "Unable to run script for $name due to unhandled exception"
|
||||
Write-Warning $psitem.Exception.StackTrace
|
||||
if ($_.Exception) {
|
||||
if (-not [string]::IsNullOrWhiteSpace($_.Exception.Message)) {
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($_.Exception.StackTrace)) {
|
||||
Write-Warning $_.Exception.StackTrace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user