问题
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