没有通过import-pssession正确导入模块

时间:2015-01-01 18:50:17

标签: windows powershell

$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和tab我得到

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是如何工作的,那就好奇了。

1 个答案:

答案 0 :(得分:1)

$s = New-PSSession -ComputerName Server01
Invoke-Command -Session $s {Import-Module Hyper-V}
Import-PSSession -Session $s -Module Hyper-V