没有通过 import-pssession 正确导入模块
Not correctly importing modules via import-pssession
$HyperVServerSession = New-PSSession -Name SERVER
Import-PSSession -session $HyperVServerSession -Module hyper-v -Prefix rhpv_
但是,当我执行 get-help rhpv_ 时,我没有显示任何包含该前缀的命令。
如果我这样做
PS C:\> get-vmhost -ComputerName SERVER
Name LogicalProcessorCount MemoryCapacity(M) VirtualMachineMigrationEnabled
---- --------------------- ----------------- ------------------------------
SERVER 12 16375.08984375 True
我可以看到我有命令。但是,如果我去键入 get-vmh 和选项卡,我会得到
PS C:\> tmp_1d1czacs.mzd\Get-VMHost computername SERVER
tmp_1d1czacs.mzd\Get-VMHost : The term 'tmp_1d1czacs.mzd\Get-VMHost' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ tmp_1d1czacs.mzd\Get-VMHost computername SERVER
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (tmp_1d1czacs.mzd\Get-VMHost:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
只是想知道我是否正确地使用了来自远程主机的导入模块,或者这是否是 PS 的工作方式。
$s = New-PSSession -ComputerName Server01
Invoke-Command -Session $s {Import-Module Hyper-V}
Import-PSSession -Session $s -Module Hyper-V
$HyperVServerSession = New-PSSession -Name SERVER
Import-PSSession -session $HyperVServerSession -Module hyper-v -Prefix rhpv_
但是,当我执行 get-help rhpv_ 时,我没有显示任何包含该前缀的命令。
如果我这样做
PS C:\> get-vmhost -ComputerName SERVER
Name LogicalProcessorCount MemoryCapacity(M) VirtualMachineMigrationEnabled
---- --------------------- ----------------- ------------------------------
SERVER 12 16375.08984375 True
我可以看到我有命令。但是,如果我去键入 get-vmh 和选项卡,我会得到
PS C:\> tmp_1d1czacs.mzd\Get-VMHost computername SERVER
tmp_1d1czacs.mzd\Get-VMHost : The term 'tmp_1d1czacs.mzd\Get-VMHost' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ tmp_1d1czacs.mzd\Get-VMHost computername SERVER
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (tmp_1d1czacs.mzd\Get-VMHost:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
只是想知道我是否正确地使用了来自远程主机的导入模块,或者这是否是 PS 的工作方式。
$s = New-PSSession -ComputerName Server01
Invoke-Command -Session $s {Import-Module Hyper-V}
Import-PSSession -Session $s -Module Hyper-V