Moving function across modules; now unable to auto-load the module

Welcome Forums General PowerShell Q&A Moving function across modules; now unable to auto-load the module

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

 
Participant
1 month, 2 weeks ago.

  • Author
    Posts
  • #169213

    Participant
    Topics: 6
    Replies: 7
    Points: 35
    Rank: Member

    I moved a function (we'll call it Get-MyFunction) from Module1 to Module2 (which I've never done before).  If I run Get-Command Get-MyFunction, it fails to find the function, but it auto-loads Module1 (which was not already loaded).  If I run Import-Module Module2, then run Get-Command Get-MyFunction, it is successful and finds it in Module2.

    Everything with the function works as expected if I manually import the Module2 first, but some cache somewhere seems to think that it is still stored in Module1.  I've confirmed there are no references in Module1's module file or manifest file (including exported commands).  What am I missing?

    This is occurring on Windows Server 2019 (PSVersion 5.1.17763.503).  I cannot recreate the problem on my Windows 10 1809 computer (PSVersion 5.1.17763.592).

    Thanks.

  • #169252

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero

    Did you try opening a new PowerShell console the Get-Command ?
    You would have already tried this, but still...

    • #169270

      Participant
      Topics: 6
      Replies: 7
      Points: 35
      Rank: Member

      Yes, I've done everything except restart the server.

  • #169297

    Participant
    Topics: 0
    Replies: 44
    Points: 235
    Helping Hand
    Rank: Participant

    can you please check server PowerShell profile if it have some reference store over there?

    How to check?
    psedit $profile
  • #169306

    Participant
    Topics: 6
    Replies: 7
    Points: 35
    Rank: Member

    Yes, I should have mentioned that.  I have no profile on the server (confirmed).  Thanks.

You must be logged in to reply to this topic.