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

Viewing 3 reply threads
  • 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: 1158
      Points: 4,045
      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: 45
      Points: 243
      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.

Viewing 3 reply threads
  • The topic ‘Moving function across modules; now unable to auto-load the module’ is closed to new replies.