Udostępnij za pośrednictwem


How to Create PowerShell Module in Easy Way

First of All what you need to do is to create 2 folders “WindowsPowerShell” and “Modules” like shown below:

“%userprofile%\My Documents\WindowsPowerShell\Modules”

Also if you tried to run

 
PS C:\Users\Raymond\Desktop> dir env:psmodulepath

you will get result like

 
Name Value
---- -----
PSModulePath C:\Users\Raymond\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPower...

Why I am showing this, To let you know that when we use command Import-Module then you write the name of the module it go and search in the folders that it’s specified in psmodulepath.

After that what you need to do using any script editor but I like Windows PowerShell ISE to write your code and then save the file but .psm1 like “ScheduleTask.psm1”

Create folder inside “%userprofile%\My Documents\WindowsPowerShell\Modules” to be like this “%userprofile%\My Documents\WindowsPowerShell\Modules\ScheduleTask”

Last step you need to copy the the psm1 file and place it inside the folder that is created in the previous step but it’s very important to make sure that the folder and psm1 file are the same name.