17

I need to install a PowerShell module (i.e. sqlserver) on one production box, however, the production server does not have any internet connection.

An alternative way I am using is to use save-module to save module files onto a shared folder and then copy the files from the shared folder directly to production server's PS module path

c:\program files\WindowsPowerShell\Modules

It works, but I am just wondering whether we can use the existing approach, i.e. install-module, something like

install-module -name sqlserver -repository "my shared folder"

This requirement extends to update-module as well.

Using save-module and then copy & paste seems very unreliable because I have no idea whether install-module will actually do some DLL file registration or installation.

Can any PS gurus please give some idea how to do this, i.e. using install-module without internet connection?

Thanks in advance for your time.

PS: I know there is a post at SO but it does not help me.

mklement0
  • 382,024
  • 64
  • 607
  • 775
jyao
  • 1,550
  • 3
  • 19
  • 26
  • 4
    https://kevinmarquette.github.io/2017-05-30-Powershell-your-first-PSScript-repository/ – TessellatingHeckler Apr 23 '18 at 18:54
  • @TessellatingHeckler, it seems very promising after 1st scan. I will try it later. On the otherhand, can you please write something in the answer section instead of comment so I can vote you up. Thanks again ! – jyao Apr 23 '18 at 20:11

2 Answers2

17
  1. In any shell (elevated or not):

     Register-PSRepository -Name 'myRepositoryName' -SourceLocation 'C:\MyExampleFolder'
    

    All .nupkg files inside your folder are now discoverable by Install-Module.

  2. In an elevated shell (Run as Administrator):

     Install-Module 'Some-Module' -Repository 'myRepositoryName'
    
Eric Eskildsen
  • 4,269
  • 2
  • 38
  • 55
  • It will work, however `SourceLocation` needs to be at least network share - it was not working for me when I've used local path. – Gucu112 Dec 01 '20 at 16:12
  • @Gucu112 Not true, you can definitely use a local path. What error message were you getting? – Eric Eskildsen Dec 02 '20 at 18:52
  • The diff between **install-module** and **import-module** seems that **import-module** can only install from a local path whereas **install-module** can install from local and from remote. – Timo Dec 16 '20 at 18:47
  • 3
    @Timo Not exactly. `Import-Module` makes a module's cmdlets accessible to you in your *current PowerShell session*. `Install-Module` *copies a module's files to a location*. Importing is like putting food on your counter to make a sandwich, whereas installing is like going shopping and bringing the food home from the store. – Eric Eskildsen Mar 05 '21 at 14:06
  • Worked for me here! My server lacks internet access, downloaded manually the nupkg file PowerShell Galley and put into a folder "C:\Temp", registered the PSRepository with "C:\Temp" as SourceLocation and installed the module. Many thanks!! – Ricardo Zambon Jul 01 '21 at 15:20
3

Eric's answer was helpful for me. I also added:

-InstallationPolicy Trusted

to the Register-PSRepository call. Taking a module and publishing it as a nuget package looks like this: Publish-Module -Name myModuleName -Repository myRepositoryName