我有一个简单的问题,但我找不到任何答案。
我正在使用 powershell 5 并且我在封闭环境中工作,无法连接到互联网,我想在我的机器上手动安装模块,基本上是任何可以下载的模块,例如 posh-ssh。
可以做到吗?让我们说在此处保存模块并安装?
由于@jyao 要求提供一些示例,以下是我的示例/示例代码答案:
在封闭网络(或离线计算机)中安装/使 PowerShell 模块可用的最简单方法是首先使用在线计算机下载所需的模块,然后将这些模块保存/复制到可从以下位置访问的位置封闭网络内。
脚步:
注意:我在以下示例中使用“ SQLServer ”模块:
Save-Module -Name "SQLServer" -Path C:\SavedPSModules
Copy-Item "C:\SavedPSModules\SQLServer" -Destination "C:\User\{usr_name}\Documents\WindowsPowerShell\Modules" -Recurse -ToSession $session;#假设目标计算机位于可访问的域/网络中,您需要为其创建一个会话(此处存储在 $session 变量中)。
Run Code Online (Sandbox Code Playgroud)#Check if module is installed & imported, do it if not: $module = "SQLServer" if((Get-Module -Name $module) -eq $null) { #Check if module is installed: if (Get-Module -ListAvailable -Name $module) { Write-Output "$module module is already installed"; #Check if module is imported: if((Get-Module -Name $module) -ne $null) { Write-Output " and is already imported (i.e. its cmdlets are ready/available to be used.)"; Write-Output "Installation Path: `n`t" (Get-Module -Name $module).Path; } else { Write-Output ", however, it is NOT imported yet - importing it now"; Import-Module $module; } }else{ Write-Output "$module module is NOT installed - installing it now" try { Install-Module -Name $module -AllowClobber -Confirm:$False -Force #suppressed prompt. } catch [Exception] { $_.message exit } Write-Output "$module installed successfully - importing it now"; Import-Module $module; } }
笔记:
$env:PSModulePath -split ';'
Mkdir C:\Users\{user_name}\Documents\WindowsPowerShell\Modules;
HTH
| 归档时间: |
|
| 查看次数: |
7034 次 |
| 最近记录: |