PowerShell Az module: export and import offline

只愿长相守 提交于 2021-02-11 14:41:15

问题


I need to move PowerShell Az module from one machine to another offline (both machines have the same windows (10 Pro 1809), .net, powershell (5.1), etc versions)

I can't use either Private PowerShellGet Repositories or MSI installer

I run Save-Module -Name Az -Path 'C:\Users\kag\Documents\ps_modules' -RequiredVersion 3.7.0 -Force on "donor" machine and it gives me 50+ dirs exported:

I copy all to "receiver" machine and running:

Get-ChildItem "C:\Users\kag\Documents\ps_modules\*" -Recurse | Unblock-File
Import-Module -name "C:\Users\kag\Documents\ps_modules\Az" -Verbose

..but getting errors for all dependencies:

Any ideas how to correctly move Az module offline?


回答1:


Here my comments as answer:

It seems the path you saved the module in C:\Users\kag\Documents\ps_modules is not one of the module paths PowerShell knows of.

You can test which paths are used by PowerShell to find your modules by typing

$env:PSModulePath.split(';')

in the console.


Below is an excerpt from Stefan Stranger's Blog

You can add a temporary path that is available for the current session only:

$env:PSModulePath = $env:PSModulePath + ";C:\Users\kag\Documents\ps_modules"

To make that permanent, you can either add the line above to your PowerShell profile, or manually add it to the registry:

$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "User")
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Users\kag\Documents\ps_modules", "User")

use "User" to store this path for the current user only. Use "Machine" to have that path available for all users



来源:https://stackoverflow.com/questions/63151918/powershell-az-module-export-and-import-offline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!