Windows PowerShell Module Directory #powershell, #module #directory, #scripting #language, #microsoft, #powershell #module #directory


PowerShell Module Directory

Introduction to PowerShell Modules

PowerShell modules are like mini-apps, they have instructions to deliver useful gismos. Configuring the path for the Import-Module cmdlet requires moderately complex preparation, and the purpose of this page is just get readers started.

PowerShell Modules Topics

You need a known path where your .psm1 modules are stored. I would start by finding $Profile. Then try PSProfilePath.

We need to start with the trickiest member of the module family ‘Import’. There are two factors to ensure success of my experiment:
a) Creating a simple test module containing PowerShell commands and with a .psm1 extension.
b) Making a note of the path to your saved .psm1 file.

Create a Test Module
Here is our test module, it has two functions ‘Grow’ and ‘Shrink’.

I suggest we call the file: Balance.psm1

Now for the key part, the path; I suggest saving this file to:

function Grow <
if(!(Test-Path variable:script:count)) < $script:count = 0 >
This is where Guy adds one <0>! -f $script:count
function Shrink <
if(!(Test-Path variable:script:count)) < $script:count = 0 >
Now Eddie takes one away <0>! -f $script:count

Import and Test

Once the PowerShell module directory is ready then you can import the code.

$Location= C:\Users\YourName\Documents\WindowsPowerShell\Modules
Import-Module $Location\Balance.psm1

When the module loads sucessfully, two functions are available; to tes them type: ‘Grow’, or ‘Shrink’.

Note 1: I introduced the $Location variable merely to highlight that you need to amend this value to suit your profile, e.g. YourName is not the correct folder. Incidentally, it seems to me that Import-Module needs the full path.

Note 2: Just to emphasise, you do need to create a file called ‘Balance’ with a modules extension (.psm1) for this to work.

Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

This displays the added, loaded, or to use the correct verb, imported modules; in this example you should see:

Note 3: If this ‘Balance’ module has loaded then you will be able to use the functions ‘Grow’ and ‘Shrink’.

Reminder of The Recommended PowerShell Module Directory

Documents folder Path \WindowsPowerShell\Modules\ Module Folder \ Files

The module manager should honour scripts marked with the appropriate Zone Identifier, as a result the modules conform the PowerShell script execution policy.

Loading Modules Automatically Through Profile

Individual user’s profiles, and programs such as ‘Word’ each have a ‘Startup’ folder; in the case of PowerShell, we can access it via the $Profile variable. Actually, there are two profile files, one for PowerShell’s ISE and another for the plain command-line PowerShell. Fortunately, you can launch notepad and edit either of them.

See All Members of the Modules Family

Get-Command -Noun module

Leave a Reply

Your email address will not be published. Required fields are marked *