Submitting and Managing Jobs with Windows PowerShell

For me, one of the most exciting new features in Windows HPC Server 2008 is our Windows PowerShell interface.  It's not only incredibly powerful, it's quite easy to learn!  And it's very useful for posting demos and examples up here.  So I figured it made pretty good sense to have my first real posting here walk through the basics of using the PowerShell interface to the Windows HPC Job Scheduler.


If you're not familiar with PowerShell at all, you may want to try checking out of the many PowerShell tutorials available out there on the net.


Let's start with the basics.  First, let's create a new job (using the New-HpcJob cmdlet) called "PowerShell Test" that is limited to a 4 hour run time and has a priority of "Above Normal":

PS> New-HpcJob -Name "PowerShell Test" -RunTime "0:4:00" -Priority "AboveNormal"


Now our job is in the system, and we'll want to add a task.  The best way to do that sort of manipulation in PowerShell is to grab hold of the actual object.  But of course I forgot to do that when I ran my New-HpcJob command.  So now I'll need to use the Get-HpcJob cmdlet to go grab my job out of the scheduler and assign it to my variable:

PS> $MyJob = Get-HpcJob -Name "PowerShell Test"


Now that the $MyJob variable has my job in it, I can go ahead and add a task.  I'll just use a simple task . . . one that runs "dir" in my home directory so I can see what I have stored in my home directory on the compute node.  I can use pipes to send my job into the Hpc-AddTask cmdlet:

PS> $MyJob | Add-HpcTask -WorkDir "%UserProfile%\Documents" -Command "dir"


Great!  Now my job is ready to go to the cluster.  There are actually two ways I can submit my job.  I can use the submission cmdlet (Submit-HpcJob), or I can call the Submit method on my job object:

PS> $MyJob | Submit-HpcJob


PS> $MyJob.Submit()


Now if you want to go ahead and see what happened to your job, you'll have a two step process.  First, call the Refresh method to update your variable with data from the server:

PS> $MyJob.Refresh()


That done, you can use the Get-HpcTask command to view the details of the tasks in your job, and the Format-List (aliased to fl) command to make that output more readable:

PS> $MyJob | Get-HpcTask | Fl


By now you might be saying, "So what?"  Well, I do still have one trick up my sleeve.  You can actually do all that with one line of PowerShell using piping.  Go ahead and try this:

PS> $MyJob = New-HpcJob -Name "PowerShell Test" -RunTime "0:4:0" -Priority "AboveNormal" | Add-HpcTask -WorkDir "%UserProfile%\Documents" -Command "dir" | Submit-HpcJob | fl


Pretty neat, eh?

Comments (0)

Skip to main content