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

1 year, 4 months ago.

  • Author
  • #84616

    Points: 14
    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

  • #84640

    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort