I understand that Powershell beginners have problems with writing Powershell modules. I had the same a few years ago. Now it’s time to tell everyone that it’s not mission impossible. First of all, you should learn about Powershell module types.
When I read my Powershell scripts which I wrote nine years ago, who wrote this. When I started with Powershell, my code didn’t contain any functions. In that time I didn’t know about any best practices during code preparing. My Powershell scripts work, and it was awesome for me.
Get know Powershell module types
Before to start writing Powershell modules, you should know all types of them. This is not required to prepare your first module, but it’s better to know this. At now it’s four Powershell module types. In 90% of scenarios, you will be preparing one of them, but it’s good to know all of them.
1. Powershell Script Module
The primary first module type is the Powershell Script Module. It’s just Powershell Script file with the psm1 extension. Probably this type you will be preparing the most often.
You can put into the text file your functions and save it as a psm1 file. When you do this, you can load all these functions to Powershell session using Import-Module command.
2. Powershell binary module
The Powershell Binary module based on C# code (programming language) so you need to compiled and saved it in a dll file. When you do this, you can load into Powershell session using Import-Module command.
This module type can be faster than the first type explained above.
This Powershell module type is more advanced so you can learn it later.
3. Powershell dynamic module
The Powershell Dynamic Module is the next one to describe. You can create it using New-Module Powershell command. It’s useful when you want to create a module in your Powershell session, but you don’t need to save it to any file.
I have to be honest that I have never used this module type. I know how it works but had never need to use it. However, it’s good to know that something like that exists in Powershell.
4. Powershell manifest module
The last one Powershell module type is Manifest Module. First of all, this module type not contain Powershell code to execute. Some people can tell that it’s not a separate Powershell module type but a way to describe another module. Maybe it’s true, but you can find it as a separate module in Microsoft documentation.
As you can see above, the Powershell has more than one module type. Probably Powershell beginners don’t know about binary and dynamic module types. You will use rarely these two types so don’t need to learn and understand it now. You can do this in the future to extend your Powershell skills.
However, you should learn how to write and use Powershell script module type.