因为在线安装Powershell其他模块速度比较慢,在线下载的模块是外网下载,所以速度会非常慢甚至无法下载
就此我们可以使用能上外网的windwos系统先下载好所需Powershell模块后,然后把下载安装好的模块拷贝出来给其他主机使用。默认powershell是禁止在线下载模块的,因为下载的地址是不受信任的,需要先开启信任后才能在线下载。如下以下载sqlserver模块为例
#在线搜索模块,如下加*便是模块搜索
Find-Module -Name VM* #以VM开头的模块
Find-Module -Name *VM* #VM在中间模块
Find-Module -Name *VM #以VM结尾的模块
#查看powershell模块在线下载的指定地址及设置
Get-PSRepository
#设置信任指定下载源地址
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
#在线安装sqlserver模块,需开启外网加速
Install-Module -Name SqlServer
#导入下载的模块,系统默认会从指定的powershell路径去搜索导入
Import-Module sqlserver
#系统默认的powershell模块路径,使用如下命令查看
$env:PSModulePath -split ';'
如下为输出的路径,一般默认在第二个目录下
C:\Users\dengpeng\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\WindowsPowerShell\Modules
#然后进入C:\Program Files\WindowsPowerShell\Modules 目录下
拷贝SqlServer整个目录到另外一台windows系统上。
C:\Program Files\WindowsPowerShell\Modules\SqlServer
建议也拷贝到C:\Program Files\WindowsPowerShell\Modules
这样所有用户都可以加载使用。
然后使用 Import-Module sqlserver 导入即可。
#扩展,如果要新添加powershell下载指定源地址
Register-PSRepository -Name MyRepo -SourceLocation 'https://example.com/MyRepo' -InstallationPolicy Trusted
#然后使用如下命令查看
Get-PSRepository