January 6, 2014

Loading (import) a module with arguments

You can use the –ArgumentList parameter of the import-module cmdlet to pass arguments when loading a module.

You should use a param bloc in your module to define your parameters :


Then call the import-module cmdlet like this :

import-module .\myModule.psm1 -ArgumentList $True,'http://www.microsoft.com'

As may have already noticed, you can only supply values (no names) to –ArgumentList. So you should define you parameters carefully with the position argument.


Rikard said...

I am trying this:
# ThisModule.psm1

PS:\> Import-Module .\ThisModule -ArgumentList "{'computerName' : 'SERVER1'}"

...and then in the module a function...
$script:ModuleSettings = $null
function ParseSettings {
$script:ModuleSettings = $ModuleSettingsAsJson | ConvertFrom-Json


ParadisJ said...

Hi Rikard,
What's your question exactly ?
Is it working ?

Post a Comment