#Requires module from UNC path

Hey everyone,

I’m trying to figure out if there is a way to specify a [pre]#Requires -Modules[/pre] to import an internally-created module from a UNC path. I’ve looked at the following documents but there is no reference to using a UNC:


I’ve attempted by referencing the module folder as well as the .psm1 files within the #Requires field, but couldn’t get it to take.

#Requires -Modules \domain.pvt\folder\moduleName\moduleName.psm1
#Requires -Modules “\domain.pvt\folder\moduleName\moduleName.psm1”
#Requires -Modules \domain.pvt\folder\moduleName
#Requires -Modules "\domain.pvt\folder\moduleName"
#Requires -Modules \domain.pvt\folder\moduleName
#Requires -Modules “\domain.pvt\folder\moduleName”

Anyone had any luck with this in the past?

According to my understanding of the Microsoft documentation you cannot specify a path for the #requires -Modules statement at all. Either you install the required modules on the computer you are about to run your script or you would have to import the module explicitly with Import-Module.

I’d agree with Olaf. The #Requires statement is expecting that the module can be traditionally imported. That’s to say that the module is located in one of the paths stored in the $env:PSModulePath environmental variable: [pre]$env:PSModulePath -split ‘;’[/pre] Speaking of which, why don’t you try adding the UNC to that environmental variable: [pre]$env:PSModulePath = “$env:PSModulePath;\Your\UNC\Path”[/pre]Maybe that test will get you what you need.

You can try working with using module <path> instead, but I’m not sure that’s designed for this either.

Realistically in a situation like this what would be best is setting up an internal module repository on a nuget server and having that package source propagated out via GPO or something, so you can just Install-Module MyModule from that on any machine in the domain, nice and easy.

Of course, you can always just Import-Module at the start of the script(s) instead, possibly checking if it’s already installed if you like.

if (-not (Get-Module MyModule)) {
    Import-Module \\server\share\MyModule

#Requires Modules from a UNC Path