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 :
param( [parameter(Position=0,Mandatory=$false)][boolean]$BeQuiet=$true, [parameter(Position=1,Mandatory=$false)][string]$URL )
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.
2 comments:
I am trying this:
# ThisModule.psm1
param(
[parameter(Position=0,Mandatory=$false)][string]$ModuleSettingsAsJson
)
PS:\> Import-Module .\ThisModule -ArgumentList "{'computerName' : 'SERVER1'}"
...and then in the module a function...
$script:ModuleSettings = $null
function ParseSettings {
$script:ModuleSettings = $ModuleSettingsAsJson | ConvertFrom-Json
}
ParseSettings
Hi Rikard,
What's your question exactly ?
Is it working ?
Post a Comment