8

I've a machine (v3, internet, no admin access) which I used to download WMF 5.0 and set up another machine(v5, no internet, admin access). Now, I want to use some modules from PowerShellGet on the machine running v5 but no internet connection.

I need an option to download *.psm1 file which I can then copy over and use. Just like we have options to download from GitHub.

Anyone with a similar issue and any workarounds ?

zerocool18
  • 523
  • 1
  • 4
  • 11
  • In order to install the packages from Powershell Gallery, you'll need the nuget package manager. To install that offline, follow this: https://learn.microsoft.com/en-us/powershell/gallery/how-to/getting-support/bootstrapping-nuget – Brain2000 Dec 01 '18 at 19:29

2 Answers2

8

Install the Package Management Module on your PowerShell 3 machine, and then use Save-Module ...

Or set up ProGet somewhere "on the edge" of your network, and have it mirror the modules you want from the public PowerShellGallery for your internal-only clients.

Failing that, just build your own download URL:

https://www.powershellgallery.com/api/v2/package/$Name/$Version

You can even generate an OData proxy module, or just use invoke-restmethod to search:

function Find-Module {
    param($Name)
    invoke-restmethod "https://www.powershellgallery.com/api/v2/Packages?`$filter=Id eq '$name' and IsLatestVersion" | 
    select-Object @{n='Name';ex={$_.title.'#text'}},
                  @{n='Version';ex={$_.properties.version}},
                  @{n='Uri';ex={$_.Content.src}}
}
function Save-Module {
    param(
        [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
        $Name,
        [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]$Uri,
        [Parameter(ValueFromPipelineByPropertyName=$true)]$Version="",
        [string]$Path = $pwd
    )
    $Path = (Join-Path $Path "$Name.$Version.nupkg")
    Invoke-WebRequest $Uri -OutFile $Path
    Get-Item $Path
}

So now you can just do the same as with the official module:

Find-Module Pester | Save-Module -Path ~\Downloads
Jaykul
  • 15,370
  • 8
  • 61
  • 70
2

Update your machine with internet access to PowerShell 5.0 and use Save-Module to save modules from PowerShellGet. Ex:

Find-Module psreadline | Save-Module -Path c:\users\frode\Desktop

This will save the module (ex. PSReadLine) to a folder which you can copy to your other machine and install like a normal module (see Installing a PowerShell Module)

Frode F.
  • 52,376
  • 9
  • 98
  • 114
  • Can't update machine with internet access to v5 else would have tried this only. Hence the question. – zerocool18 May 27 '16 at 20:59
  • Question never said you couldn't, just that you had not done it yet. Why can't you update it? Get someone else to do it or install the powershellget module for ps3.0 (https://www.microsoft.com/en-us/download/details.aspx?id=51451). If you aren't allowed to do any of the suggestions then it sounds like you probably aren't allowed to install 3rd party modules at all. – Frode F. May 27 '16 at 21:14
  • I can install 3rd party stuff on a machine but that's not connected to inernet. But, can't make any changes/or ask anyone to make changes to machine that is connected to internet. Any idea where I can get .psm1 files directly ? – zerocool18 May 31 '16 at 09:07