PowerShell V4 / Modules directory structure?

Welcome Forums General PowerShell Q&A PowerShell V4 / Modules directory structure?

Viewing 3 reply threads
  • Author
    Posts
    • #208899
      Participant
      Topics: 17
      Replies: 24
      Points: 80
      Rank: Member

      Recently i created a module, added it to azure devops.

      Everything works great, I subscribe to the feed, added it as a repository (after additional problems required installing

      AzureArtifactModule

      I was able to get the module pulled down local and autoload great in v5.

      However in v4 i wasnt seeing the module.

      The directory was

      C:\Program Files\WindowsPowershell\Modules\ModuleTest\0.1.1.0\moduletest.psm1

      I tried alot of things and finally thought what if i move it to

      C:\Program Files\WindowsPowershell\Modules\ModuleTest\moduletest.psm1

      I did this and life was happy, however i would like thoughts on best way to do this for all powershell versions and if possible without having to give up module version folder name.

       

      Thank you

      Jason

      • This topic was modified 2 months, 3 weeks ago by Jason McMahan.
    • #208929
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      With a directory path ModuleTest\0.1.1.0\moduletest.psm1, the goal would be to have multiple versions under the same module? Typically, the PSM1 and PSD1 are in the root of the module directory. The module version is identified in the PSD1, not traditionally in the folder structure that is client-side. In the repo, there may be a version structure like 0.1.1.0\ModuleTest\moduletest.psm1, but the repository would just use that as the latest version.

    • #209136
      Participant
      Topics: 17
      Replies: 24
      Points: 80
      Rank: Member

      Thank you for the reply Rob,

      I was thinking that as well but following this article unless i misunderstood it it will work on v5 but the problem is prior it will not work.

      So its like ok then how to separate v5 from prior version and do something at download so prior versions can see the modules.

      https://docs.microsoft.com/en-us/powershell/scripting/developer/module/installing-a-powershell-module?view=powershell-7

       

    • #209232
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      Personally not had multiple versions under a single module, but I think the key is that you have to add references to the individual modules.

      $p = [Environment]::GetEnvironmentVariable("PSModulePath")
      $p += ";C:\Program Files\Fabrikam\Fabrikam8;C:\Program Files\Fabrikam\Fabrikam9"
      [Environment]::SetEnvironmentVariable("PSModulePath",$p)
      

      Powershell 5 module search may parse this structure without adding the entries above, but Powershell 4 or lower need specific references for additional roots to search. My guess is the logic is Powershell is doing a Get-ChildItem search in Powershell 4 and Powershell 5 is doing a -Recursive search for modules.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.