2015-11-05 30 views
0

我已經創建一個遠程會話,我可以在會議無法導入PSSession進行「管理」?

$session = New-PSSession -ComputerName S1 
Invoke-Command -ScriptBlock { Get-ChildItem c:\ } -Session $session 

現在我想做到以下幾點,以方便打字運行的腳本塊。

Get-S1ChildItem c:\ 

所以我做了以下

Import-PSSession -Session $session -Module management -Prefix S1 

但是,它有以下錯誤。

 
Import-PSSession : Running the Get-Command command in a remote session returned no results. 
At line:1 char:1 
+ Import-PSSession -Session $session -Module management -Prefix S1 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidResult: (:) [Import-PSSession], ArgumentException 
    + FullyQualifiedErrorId : ErrorNoResultsFromRemoteEnd,Microsoft.PowerShell.Commands.ImportPSSessionCommand 

回答

1

對我來說,與-Module 'Microsoft.PowerShell.Management'更換-Module management時工作正常。爲了能夠使用遠程CmdLets,Invoke-Command並不是真的需要。

請嘗試以下方法:

$session = New-PSSession -ComputerName S1 
Import-PSSession -Session $session -Prefix S1 -Module 'Microsoft.PowerShell.Management' 
Get-S1ChildItem c:\ 

這證明,從遠程會話模塊Microsoft.PowerShell.Management在所有cmdlet都可用,如在Import-PSSessionhelp描述。

要找出哪個模塊cmdlet才能找到,你可以使用:

Get-Command Get-ChildItem | Select-Object ModuleName