Unable to Import-Module with -ArgumentList

This topic contains 2 replies, has 3 voices, and was last updated by  Pradeep Arora 3 weeks, 5 days ago.

  • Author
    Posts
  • #84616

    Derf User
    Participant

    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.

  • #84638

    Don Jones
    Keymaster

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

  • #84640

    Pradeep Arora
    Participant

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

You must be logged in to reply to this topic.