Tutorial by Examples

@{ RootModule = 'MyCoolModule.psm1' ModuleVersion = '1.0' CompatiblePSEditions = @('Core') GUID = '6b42c995-67da-4139-be79-597a328056cc' Author = 'Bob Schmob' CompanyName = 'My Company' Copyright = '(c) 2017 Administrator. All rights reserved.' Description = 'It does cool stu...
function Add { [CmdletBinding()] param ( [int] $x , [int] $y ) return $x + $y } Export-ModuleMember -Function Add This is a simple example of what a PowerShell script module file might look like. This file would be called MyCoolModule.psm1, and is referenced from the mod...
$FirstName = 'Bob' Export-ModuleMember -Variable FirstName To export a variable from a module, you use the Export-ModuleMember command, with the -Variable parameter. Remember, however, that if the variable is also not explicitly exported in the module manifest (.psd1) file, then the variable wil...
Rather than defining all of your functions in a single .psm1 PowerShell script module file, you might want to break apart your function into individual files. You can then dot-source these files from your script module file, which in essence, treats them as if they were part of the .psm1 file itself...
PowerShell looks for modules in the directories listed in the $Env:PSModulepath. A module called foo, in a folder called foo will be found with Import-Module foo In that folder, PowerShell will look for a module manifest (foo.psd1), a module file (foo.psm1), a DLL (foo.dll).
By default, only functions defined in a module are visible outside of the module. In other words, if you define variables and aliases in a module, they won't be available except in the module's code. To override this behavior, you can use the Export-ModuleMember cmdlet. It has parameters called -F...

Page 1 of 1