If ALL out-sourced Microsoft module developers were required to adopt a structured versioning system, for all versions of their PowerShell modules – using sub-folders for version differentiation, it would greatly enhance modularity and compatibility across different PowerShell versions.
Current Structure
In our example, the directory for the Microsoft.Graph.Users.Functions module already looks like this:
C:\Users\burwell\Documents\PowerShell\modules\Microsoft.Graph.Users.Functions
├── 2.28.0
├── 2.30.0
└── 2.32.0
Benefits of Sub-Folder Versioning
- Seamless Side-Loading Compatibility:
- By allowing multiple versions to coexist (side-loading), users can easily switch between versions without conflicts. PowerShell could dynamically load the appropriate version based on the environment (5.1 or 7.x).
- Targeted Features:
- Users then take advantage of features specific to their PowerShell version; newer modules utilize functionalities exclusive to PowerShell 7.x, while ensuring legacy systems with PowerShell 5.1 still operate effectively with the older, compatible versions.
- Minimized Upgrade Risks:
- Upgrading a module would no longer require replacing the existing version, thus mitigating risks associated with changes in functionality or behavioral shifts between versions (esp. for Active Directory Domain Controllers and legacy app servers).
Practical Implementation
If Microsoft PowerShell development implemented versioning standardization, side-loading modules would be straightforward.
- Importing Modules: PowerShell could include logic to resolve the correct version based on the executing PowerShell host, making imports look like this:
# For PowerShell 5.1
Import-Module "C:\Users\burwell\Documents\PowerShell\modules\Microsoft.Graph.Users.Functions\2.28.0"
# For PowerShell 7.x
Import-Module "C:\Users\burwell\Documents\PowerShell\modules\Microsoft.Graph.Users.Functions\2.32.0"
Conclusion
The proposed sub-folder versioning method could significantly streamline the user experience and reduce compatibility headaches, especially in mixed environments. It would also foster a far more robust development practice, benefitting both the module developers and end-users alike, by enhancing flexibility and minimizing disruption during upgrades. This strategy could be instrumental in fostering a more modular and resilient PowerShell ecosystem.
