Donnerstag, 11. Februar 2010

Ise Menu for Backgroud Jobs (Trial)

The following code is inspired by the planned articels from Ravikanth Chaganti about Background Jobs. If 'Run as Job' and 'Run selection as Job' would run it would be cool. But I don't see the difference to 'local background job (demo)' which is running. As in previous post get Add-IseMenu from ISEPack.

function Update-PSJobMenu()            
{
$jobs = Get-Job

if ($jobs)
{
$receive_Job_items = @{}
$stop_job_items = @{}
$remove_job_items = @{}
$jobs | % {
$receive_job_items[$_.name] = "Get-Job -id $([int] $_.Id) | Receive-Job "
$stop_job_items[$_.name] = "Stop-Job -id $([int] $_.Id) | Stop-Job "
$remove_job_items[$_.name] = "Remove-Job -id $([int] $_.Id) | Receive-Job ; Update-PSJobMenu "
}
}

$items = @{
"Get-Info" = { Get-Job }

# temporary until the next 2 are working and renamed to a common path
"local background job (demo)" = {
Invoke-Command -computer localhost -ScriptBlock {(Get-ChildItem C:\windows -Recurse).Count} -asJob
Update-PSJobMenu
}
# not working, but would be very cool
"Run as Job" = {
$cmd = $psIse.CurrentFile.Editor.Text
Invoke-Command -computer localhost -ScriptBlock {$cmd } -asJob
Update-PSJobMenu

}
# not working, but would be very cool
# gci C:\windows -rec
"Run selection as Job" = {
$cmd = $psIse.CurrentFile.Editor.SelectedText
Invoke-Command -computer localhost -ScriptBlock {$cmd } -asJob
Update-PSJobMenu
}

"Stop-Job" = $stop_job_items
"Remove-Job" = $remove_job_items

"Receive-Job id" = $receive_job_items
"Refresh Menu" = { Update-PSJobMenu }
}

Add-IseMenu -name PSJobs $items
}


Update-PSJobMenu



I tell me would what I have to do to fix this. Many thanks in advance.

Bernd

Keine Kommentare:

Kommentar veröffentlichen