Mittwoch, 10. Februar 2010

PSRemoting & ISE (I)

If you weant to learn about PSRemoting read Ravikanth's PowerShell 2.0 remoting guide.

When you have
Enter-PSSession -ComputerName localhost

running (cf. part 3) and you have PowerShell V2 with ISE running check whether you haveISEPack installed.

Then you can try the following function which puts some remoting commands to you addon menu:

Add-IseMenu -name    Remoting  @{            
"Get-PSSessionConfiguration" = { Get-PSSessionConfiguration }

"Enter-PSSesion localhost" = { Enter-PSSession localhost }
"Enter-PSSession " = {
Enter-PSSession -ComputerName (Read-Host "Enter computerName: ")
if (! $?){
Enter-PSSession -ComputerName (Read-Host "Enter computerName: ") -Credential (Get-Credential)
}
}
"Enter Session Id 1" = { Enter-PSSession -Session (Get-PSSession -Id 1)}
"Enter Session Id 2" = { Enter-PSSession -Session (Get-PSSession -Id 2)}

"Exit-PSSession" = { Exit-PSSession }
"Get-PSSession" = { Get-PSSession }
"New-PSSession localhost" = { New-PSSession localhost }
"New-PSSession " = {
New-PSSession -ComputerName (Read-Host "Enter computerName: ")
if (! $?){
New-PSSession -ComputerName (Read-Host "Enter computerName: ") -Credential (Get-Credential)
}
}

# "background cmd test 1" = { Invoke-Command -Session (Get-PSSession -Id 1) -ScriptBlock {(Get-ChildItem C:\var -Recurse).Count} -asJob }
"background cmd local" = { Invoke-Command -computer localhost -ScriptBlock {(Get-ChildItem C:\var -Recurse).Count} -asJob }
"Get-Job" = { Get-Job }
"Get-Job 1" = { Get-Job -id 1 | Receive-Job }
"Import Session1 " = {Import-PSSession -Session (Get-PSSession -Id 1) -Prefix RS }
}


I think this is rather basic. Most of it runs in the local session.
But note the Exit-PSSession entry, which is prepared in the local session, but invoked from the remote session.

Generally while in remote session, you can't acces $psISE (or I didn't yet find a work around).
So while in remote session you can not modify the addon menu.
( For dynamic modifying of the addon menu see my module loader http://pauerschell.blogspot.com/ )

I hope that helps you play with PSRemoting using ISE.

Just extended the code. Thanks to Ravi.

Keine Kommentare:

Kommentar veröffentlichen