I have an Azure Automation PowerShell runbook that calls particular child runbooks based on input parameters. The child runbooks perform actions with different PowerShell modules. I believe Azure Automation is automatically loading/importing the required modules at the moment the child runbook is called. I would like to prevent this behaviour, and import modules manually using import-module.
In an Azure Automation account, is it possible to control if/when required modules are imported?
Edit:
Microsoft documentation outlining conditions where modules are imported.
This behavior, in Powershell, is controlled by one of the preference variables. More specifically, the
$PSModuleAutoloadingPreferencevariable.This variable control the automatic importing of module in the session. By default, it is set to
All, which automatically import modules on first-use.Set this to
Noneto disable the automatic importing of modules. You will need to explicitely useImport-Modulefor any command to be loaded.Here's a snippet of the official documentation regarding preferences variiables and that variable specifically.
About Preference Variables
...
Source: about_Preference_Variables