6

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?

Junaid
  • 583
  • 6
  • 19
  • Check this link and see if it satisfies your requirement http://windowsitpro.com/blog/powershell-implicit-remoting-never-install-module-again – Nkosi Sep 16 '16 at 02:12
  • Thanks for the reply but unfortunately that won't work for me. My script will be run on customer environments to quickly discover network devices etc. So I can't remote from their machines to ours. – Junaid Sep 16 '16 at 03:47
  • But what about having it on one central server in their environment and having the rest use that. I know it seems like a hack but it could be a viable workaround. – Nkosi Sep 16 '16 at 03:49

1 Answers1

7

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).

qbik
  • 5,502
  • 2
  • 27
  • 33