As an example I have a module called web-utils
, let's say I do some updates to it and I need to reload it like "module reload explained here". I have created a function
function Module-Reload([string]$name) {
Remove-Module -Name $name -Force -WarningAction SilentlyContinue
Import-Module -Name $name -Force -WarningAction SilentlyContinue
}
which throws an error as module name contain a hyphen, the question is: is there a way automatically escape hyphen in variables value? or is there another way of passing such parameters? As Import-Modules -Force web-utils
works flawlessly only when it's typed manually in CLI. In case of doing it via function results in the following:
Import-Module : The specified module 'web`-utils' was not loaded because no valid module file was found in any module directory. At WindowsPowerShell\Aliases.ps1:35 char:3 + Import-Module -Name $value -Force -WarningAction SilentlyContinue + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (web`-utils:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand