Junaid
Junaid

Reputation: 603

PowerShell Use third party module without installing it

I am sure this would be possible but can't find anything useful. I have written a lan scanner script. To automate things as much as possible, I don't rely on any input from user. The script checks the local interface IP address and uses Indented Network Tools module to calculate the number of possible IP addresses and pings each one.

The problem is since I am using a third party tool, I have to install it on any machine that I want to use this script on. Is there a way I can include this third party module with my script like put them in the same folder and not have to install it separately?

Upvotes: 6

Views: 5231

Answers (1)

qbik
qbik

Reputation: 5938

That really depends on how you want to deploy your module to other machines. If you want to share it on a network share or distribute a zip package, then you can include these dependencies along with your module. Just put Indented.Common and Indented.NetworkTools in one directory with your script definition, like so:

MyModule/
└╴MyModule.psm1
└╴Indented.Common/
└╴IndentedNetworkTools/

Then, you can load these modules directly from MyModule.psm1 (without installing them to a global modules path):

import-module $psscriptroot\Indented.Common\Indented.Common.psm1
import-module $psscriptroot\Indented.NetworkTools\Indented.NetworkTools.psm1

And that's it. This will also work if you have a normal .ps1, not a .psm1 module.

Perhaps a more elegant way would be to use WMF5 PackageManagement. Declare Indented.NetworkTools as dependencies (NestedModules) in MyModule.psd1, then publish it on PSGallery. Then, you can just say Install-Module MyModule on other machines - this will install MyModule and it's dependencies.

The problem with this approach is that any declared dependencies have to be also available on PowershellGallery (which Indented.* modules are not).

Upvotes: 7

Related Questions