azureautomation / runbooks

Sample Automation runbooks
MIT License
154 stars 129 forks source link

Powershell Runbook cannot process "using module" command #111

Closed htwashere closed 2 weeks ago

htwashere commented 2 weeks ago

Problem

I have created a powershell script that imports a module. In order to import classes, I need to use the "using module" command as per microsoft documentation. My powershell script (ps1) works fine locally with the command but when I import it into an Azure runbook, I get the error "Could not find the module" or error "The given assembly name or codebase was invalid. (0x80131047)" on the using statement.

Set Up

I have created my own runtime environment (currently under preview in Azure) using powershell 7.2. In the runtime, I have successfully imported my modules. In my PS1 script, I run the command "get-module -ListAvailable" and I can see that my modules are imported successfully. If I do "import-module", it works. But "using module" will not.

htwashere commented 2 weeks ago

After two days of painful debugging, this finally works for me. I need to surround the module name using quotes. For example: using module "MyModule".