Why are PowerShell Import-Module wildcards not working?

789 Views Asked by At

I have a few scripts where I import all VMware-Modules for simplicity. This has worked all the time - but now on one server it won't.

PS C:\Temp> Import-Module VMware.*
Import-Module : The specified module 'VMware.*' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ Import-Module VMware.*
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (VMware.*:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

I just copied the modules to C:\Windows\System32\WindowsPowerShell\v1.0\Modules.

When I use the full name (Import-Module VMware.VimAutomation.Core) it works as usual.

How can I fix this? They appear correctly when I do a Get-Module -ListAvailable.

1

There are 1 best solutions below

0
On

Import-Module doesn't support wildcards. What you could do, however, is get all the module names using Get-Module and then pipe them into a ForEach-Object command.

I believe this will achieve what you are after:

Get-Module -Name "VMWave.*" | ForEach-Object { Import-Module $_; Write-Host "Imported Module $_"}