Author Posts

November 20, 2017 at 9:10 am

PowerShell 5; Windows 7.
I have a simple psm1 module and cannot import it with arguments. I have read somewhere that this is possible with the -ArgumentList parameter:

function Test-Module {
    param([String]$newFile = 'C:\test')
    Write-Warning $newFile
}

I have tried Import-Module -Name Test-Module -Force -ArgumentList 'd:\Something' but
this is not working as it always outputs 'C:\test'. I am obviously missing something very simple. Any ideas please?
I can now answer this myself: The param line needs to be before the function call and it all works.

November 20, 2017 at 2:38 pm

Correct. As shown, your parameter is for the function, not the script itself.

November 20, 2017 at 3:35 pm

Sorry you are not even close to the answer. You need to go read the book or watch the mva videos.