Skip to content

Latest commit

 

History

History
103 lines (62 loc) · 4.19 KB

How_to_install_WASP_as_module_in_PowerShell.md

File metadata and controls

103 lines (62 loc) · 4.19 KB

How to install WASP as module in PowerShell

This is an instructional summary of how to install the WASP as a module. Adapted from Robert Allen's tutorial on Active Directory Pro.1

  1. Choose your module install path
  2. Ensure DLL is in the WASP directory
  3. Copy WASP DLL to module path and unblock it
  4. Import new module

Step 1: Choose your module install path

Install new modules in a path that is listed in the PSModulePath environment variable. To see the value of PSModulePath run the following command.

$env:PSModulePath -split ';'

Here is the result of running that command on my computer. You should see similar results.

$env:ProgramFiles\WindowsPowerShell\Modules<Module Folder><Module Files>

There may be several paths listed but there are two main paths you should use, they are:

  1. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\
  2. $env:ProgramFiles\WindowsPowerShell\Modules\<Module📁>\<Module📃📄's>

Use the first path if you want the module to be available for a specific user. Use the second path to make the module available for all users.

What are the other paths for?

The path below is reserved for modules that ship with Windows. Microsoft recommends not using this location.

PowerShell

$PSHome\Modules

CMD

%Windir%\System32\WindowsPowerShell\v1.0\Modules

You can also add your own paths, but unless you have a specific need, just stick with the two listed.

If you see other paths listed in your environment variable, it may be from programs you have installed. Some programs will automatically add PowerShell commands to the variable after installation.

Now that we know where to put new modules, let's move to step 2.

Step 2: Ensure DLL is in the WASP directory

Check that you have the WASP.dll from the releases in the WASP module directory. DLL in WASP module path

Step 3: Copy WASP DLL to module path and unblock it

The next step is to copy WASP containing the WASP.dll into one of the two paths identified in step 1. Here, we'll make it available to all users by copying it to the $env:ProgramFiles destination

C:\Program Files\WindowsPowerShell\Modules

Powershell Module Install

There it is. Copy and paste or extract the module into the path.

We also need to ask Windows to unblock the DLL, since the file is originally downloaded from the Internet.

Unblock-File -Path "$env:ProgramFiles\WindowsPowerShell\Modules\WASP\WASP.dll"

Now let’s verify the new module is visible to PowerShell, run the following command:

Get-Module -ListAvailable

This command will check the paths that are set in the environment variable for modules.

The screenshot below is what returns when I run this command. I can see that the new module (WASP) is now visible to PowerShell.

Result of list modules

Now that the new module is installed we still have one final step before we can use the new commands.

Step 4: Import new module

Importing loads the module into active memory so that we can access the module in our session.

To import run the following command

Import-Module -name WASP

That will do it — the WASP module is now ready to use.

if(Get-InstalledModule -Name WASP -ErrorAction Ignore) {Get-Module -ListAvailable -Name WASP | Import-Module} else {Write-Host "You need to install the module first. See https://github.com/mavaddat/wasp/How_to_install_WASP_as_module_in_PowerShell.md" -ForegroundColor Red}

1: Allen, Robert. “How to Install PowerShell Modules.” Active Directory Pro, Active Directory Pro, 9 June 2018, activedirectorypro.com/install-powershell-modules/.