Guy recommends :
Free SolarWinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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

Creating the Special PowerShell Module Folder

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

# PowerShell profile
Clear-Host
$Profile
$PSProfilePath

Import-Module

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:
C:\Users\YourName\Documents\WindowsPowerShell\Modules

function Grow {
if(!(Test-Path variable:script:count)) { $script:count = 0 }
$script:count++
"This is where Guy adds one {0}!" -f $script:count
}
function Shrink {
if(!(Test-Path variable:script:count)) { $script:count = 0 }
$script:count--
"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.

Clear-Host
$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 : SolarWinds' Free VM MonitorSolarwinds VM Console Free Download

The great feature of this new this new version of SolarWinds VM Monitor is that it checks Windows Hyper-V.  Naturally, it still works with virtual machines on VMware ESX Servers.  VM Monitor is an nifty desktop tool that not only tests that your server is online, but also displays the CPU and memory utilization for each node.

It's easy to install and to configure this virtual machine monitor, all you need the host server's IP address or hostname and the logon info.

Download your free copy of SolarWinds VM Monitor.

Get-Module

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

ModuleType Name ExportedCommands
---------- ---- ----------------
Script     Balance  {Grow, Shrink}

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 mark scripts as with the appropriate Zone Identifier, so that the conform the PowerShell script execution policy.

Loading Modules Automatically Through Profile

Most programs from the operating system to applications such as 'Word' have a startup folder; in the case of PowerShell, we can access it via the $Profile variable.  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.

The Plan
Open Microsoft.PowerShell_profile with notepad
Append an Import-Module command
See details of how to modify a PowerShell Profile.

See All Members of the Modules Family

Clear-Host
Get-Command -noun module

  • Get-Module
  • New-Module
  • Import-Module
  • Remove-Module

See more examples of Import-Module »

Summary of PowerShell Modules Directory

The Import-Module cmdlet works nicely when it has the correct path configured. The secret is to research the location of $Profile and $PSProfilePath. As for the big picture, PowerShell modules are like apps.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell 'where'  • PowerShell 'Sort'

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, SolarWinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2012 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: