Unable to Import-Module with -ArgumentList

Welcome Forums General PowerShell Q&A Unable to Import-Module with -ArgumentList

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #84616

    Participant
    Points: 1
    Rank: Member

    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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

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

  • #84640

    Participant
    Points: 0
    Rank: Member

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

The topic ‘Unable to Import-Module with -ArgumentList’ is closed to new replies.