Skip to content

Commit

Permalink
Update Install-CommandNotFoundUtility.ps1
Browse files Browse the repository at this point in the history
Wrap installation in try block.
  • Loading branch information
SamErde authored Feb 9, 2025
1 parent bc8f330 commit 80256c5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PSPreworkout/Public/Install-CommandNotFoundUtility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function Install-CommandNotFoundUtility {
.NOTES
Author: Sam Erde
Version: 0.1.0
Modified: 2025-01-07
Version: 0.1.1
Modified: 2025-02-08
#>
#requires -version 7.4
[CmdletBinding(HelpUri = 'https://day3bits.com/PSPreworkout/Install-CommandNotFoundUtility')]
Expand All @@ -23,8 +23,13 @@ function Install-CommandNotFoundUtility {
} # end begin block

process {
Install-Module -Name Microsoft.WinGet.CommandNotFound -Scope CurrentUser
try {
Install-Module -Name Microsoft.WinGet.CommandNotFound -Scope CurrentUser -Force
catch {
throw $_
}
try {
# Might need to remove this to avoid errors during PSPreworkout installation.
Import-Module -Name Microsoft.WinGet.CommandNotFound -ErrorAction SilentlyContinue
} catch [System.InvalidOperationException] {
Write-Warning -Message "Received the error `"$_`" while importing the 'Microsoft.WinGet.CommandNotFound module. The module may have already been installed and imported in the current session. This can usually be ignored.`n"
Expand Down

0 comments on commit 80256c5

Please sign in to comment.