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.
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 }
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 Monitor
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.
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 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
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.
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.