I already create a remote session and I can run script block on the session
$session = New-PSSession -ComputerName S1
Invoke-Command -ScriptBlock { Get-ChildItem c:\ } -Session $session
Now I want to do the following for easier typing.
Get-S1ChildItem c:\
So I did the following
Import-PSSession -Session $session -Module management -Prefix S1
However, it got the following error.
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
For me it works fine when replacing -Module management
with -Module 'Microsoft.PowerShell.Management'
. The Invoke-Command
is not really needed, to be able to use remote CmdLets.
Please try the following:
$session = New-PSSession -ComputerName S1
Import-PSSession -Session $session -Prefix S1 -Module 'Microsoft.PowerShell.Management'
Get-S1ChildItem c:\
This proves that all CmdLets from the remote session in the module Microsoft.PowerShell.Management
are available, as described in the help of Import-PSSession
.
To find out in which module a CmdLet can be found, you can use:
Get-Command Get-ChildItem | Select-Object ModuleName
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments