microsoft/winget-cli-restsource

The Test-PowerShellModuleExist function is irrelevant and should be removed

JimMoyle opened this issue · 0 comments

Brief description of your issue

PowerShell provides a native way to check for required modules and a separate function isn't needed as documented here:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-7.4#-modules-module-name--hashtable
The entire test logic for the modules can be replaced by the single line:

#Requires -Modules Az.Resources, Az.Accounts, Az.Websites, Az.Functions, Az.Storage

This line can be placed anywhere in the script, but goes into the begin block by convention.

I will improve the script be bringing it inline with PowerShell standards and making it quicker to error when the modules are not present.

Steps to reproduce

Remove the module test logic and replace with the single line above

Expected behavior

the module cannot be loaded without the modules being present

Actual behavior

module loads, but fails on initial run.

Environment

N/A