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.
SolarWinds Firewall Browser
Here is an utility where you can review firewall settings such as
access control lists (ACL), or troubleshoot problems with network
address translation (NAT).
Other reasons to download this SolarWinds Firewall Browser include
managing requests to change your firewall settings, testing firewall
rules before you go live, and querying settings with the browser's
powerful search options.
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.
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
Windows Management Instrumentation (WMI) is
most useful for PowerShell scripting.
SolarWinds
have produced this
Free WMI Monitor to take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.