PowerShell v5 - 如何将模块安装到没有互联网连接的计算机上? [英] PowerShell v5 - How to install modules to a computer having no internet connection?

查看:32
本文介绍了PowerShell v5 - 如何将模块安装到没有互联网连接的计算机上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台机器(v3,互联网,没有管理员访问权限),我用来下载 WMF 5.0 并设置另一台机器(v5,没有互联网,管理员访问权限).现在,我想在运行 v5 但没有互联网连接的机器上使用 PowerShellGet 中的一些模块.

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.

我需要一个下载 *.psm1 文件的选项,然后我可以复制并使用该文件.就像我们可以选择从 GitHub 下载一样.

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 ?

推荐答案

安装 Package Management Module 在您的 PowerShell 3 机器上,然后使用 Save-Module ...

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

或者在您网络的边缘"某处设置 ProGet,并让它镜像您想要的模块来自公共 PowerShellGallery,供您的内部客户使用.

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.

否则,只需构建您自己的下载 URL:

Failing that, just build your own download URL:

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

你甚至可以生成一个 OData 代理模块,或者直接使用 invoke-restmethod 来搜索:

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

这篇关于PowerShell v5 - 如何将模块安装到没有互联网连接的计算机上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆