Microsoft Compute Cluster now has a PowerShell Provider and Cmdlets

Today the Compute Cluster group announced the release of their Tool Pack HERE. This includes a monitoring tool, a ping/pong diagnostic tool and (drum roll please……) a PowerShell Snap-in which provides a provider and a set of commands. I really like what they have done. I’ve include the text of their about file so that you can see for yourself.

Here is a test – take a look at the file below but don’t read any of the text – just look at the command examples.

See if you can figure out what it is doing. Now go back and read it again with the text and ask yourself whether the text really added a lot more to your understanding.

Let me be very quick to state that I’m NOT making the case against documentation. Heavens no! Great documentation is super important. What I’m trying to point out is the self-documenting nature of PowerShell scripts. This is why we are so hard core about the naming guidelines.

At some point, the mess is going to hit the fan and you are going to be under lots of pressure to figure out what a script is doing and modify it to meet some new requirement. We’ve all been there before, trying to figure out what the heck a script is doing. Now imagine that same scenario but the script is written in PowerShell. We are working our butts off to make sure that that is a good experience for you.

BTW (I’m going to keep reminding you of this) you all play a super important role in making this come true. When you see anyone produce Cmdlets or Scripts which don’t conform to the naming guidelines – you should scream! Chaos is the natural state of things and everyone is going to argue that their world is “special” and they need their own terms. If you accept that, then we’ll end up with yet another incoherent mess. What those people should do is to use the standard terms and then define aliases from their “special” terms to the standard terms.

Anyway – I love what they have done with PowerShell. It’s another example of a team delivering a great experience using PowerShell.

— A set of CCP cmdlets for Windows PowerShell, including Get-Node, Get-Job, Get-Task, New-Job, and New-Task.

NAVIGATING CCP DATA IN WINDOWS POWERSHELL

You can use the features added by the CCP snap-in to manage CCP cluster in Windows PowerShell.

The following command creates a new Windows PowerShell drive called CCP: and mounts a cluster onto the Windows PowerShell CCP: drive. The cluster is identified by its head node, which is stored in the value of the CCP_SCHEDULER environment variable.

New-PSDrive -name CCP -provider CCPProvider -root $Env:CCP_SCHEDULER

After the drive is created, you can switch to this drive and access the data as though it were located in the drive.

For example, the following command changes to the new CCP: drive. It uses the “cd” alias for the Set-Location cmdlet, and the “dir” alias for the Get-Childitem cmdlet.

The CCP cmdlets lets you manage clusters in Windows PowerShell. All of the CCP cmdlets have a Scheduler parameter that specifies the head node that the command affects.

If the Scheduler parameter is not included in the command, the CCP cmdlets use the value of the CCP_SCHEDULER environment variable ($ENV:CCP_SCHEDULER)as the default head node. You can use the Set-Content cmdlet to change the value of CCP_SCHEDULER.

For help with any cmdlet, at the Windows PowerShell prompt, type:

get-help <cmdlet-name>”

For example:

get-help get-node

Get-Node: Gets all of the nodes under the head node.

This command uses the Get-Node cmdlet to list all of the nodes under the head node.

Enable-Node: Approves any pending nodes under the head node. This changes the status of the node from Pending to Paused. Use the Resume-Node cmdlet to make them ready.

The first command in this example uses the Get-Node cmdlet to get all of the nodes under the head node. Then, it uses the pipeline operator (|) to send the results of the Get-Node command to the Enable-Node cmdlet, which approves the pending nodes. As a result, the nodes that were in a Pending status are now in a Paused status.

The second command uses the Get-Node cmdlet to display the updated status of the nodes.

Resume-Node: Resumes any paused nodes under the head node. This changes their status from Paused to Ready. Because newly-enabled nodes are paused, you need to use this cmdlet to change their status to Ready.

The first command in this example uses the Get-Node cmdlet to get all of the nodes under the head node. Then, it uses the pipeline operator (|) to send the results of the Get-Node command to the Resume-Node cmdlet, which enables any paused nodes. As a result, the nodes that were in a Paused status are now in a Ready status.

You can save a collection of nodes in a variable and use array notation to viewand manage the node objects. (For more information, type “get-help about_shell_variable” and “get-help about_array”.)

This command uses the assignment operator (=) to save the results of the Get-Node command in the $a variable.

PS ccp:\> $a = get-node

This command displays the first node (element 0) in the $a variable.

PS ccp:\> $a[0]

Name Status Proc Idle —- —— —- —- HPC-DEMO-CN-11 Ready 2 2

You can use the Windows PowerShell filtering cmdlets, such as Select-Object, Where-Object, and Sort-Object, to manage CCP data.

The first command uses the Select-Object to assign only the first two nodes in the collection to the $a variable. Because the pipeline operator (|) has precedence over the assignment operator (=), the “get-node | select-object first 2″ part of the command is completed first and the results are assigned to the $a variable.

Suspend-Node: Suspends ready nodes. This changes their status from Ready to Paused.

The following command uses the Select-Object cmdlet and its First parameter to select only the first three nodes returned by Get-Node. The second pipeline operator in the command sends the objects representing the three nodes to Suspend-Node, which pauses the nodes.

The second Get-Node command confirms that Suspend-Node affected only the first three nodes.

This command gets all of the jobs under the head node. It uses the pipeline operator (|) to send the jobs to the Restart-Job cmdlet, which restarts any jobs that not started. As a result, a job that had failed is now requeued.

Unlike the Start-Job cmdlet, the Restart-Job cmdlets starts only jobs that were started, but failed, were cancelled, or were suspended.

This command gets all of the jobs under the head node. It uses the pipeline operator (|) to send the jobs to the Stop-Job cmdlet, which stops the jobs that it receives. As a result, a job that had been queued is now cancelled.

This command gets the tasks in a job and displays them in order by task ID.

This command uses the Get-Job cmdlet to get the jobs under the head node. It uses array notation to select the second job ([1] in a zero-based array). The pipeline operator (|) sends the job to the Get-Task cmdlet, which gets all of the tasks in the job and sends them to the Sort-Object cmdlet, which sorts them in order by task ID.

By default, tasks are displayed in the order that they are discovered.

This command gets the tasks in a selected job and uses the Where-Object cmdlet to select only the tasks with IDs greater than 500 and less than 530.

The Where-Object command uses the “$_.” notation, which refers to the current object in the pipeline. The pipeline operator sends objects down the pipeline one at a time. The “$_.” notation indicates that the operation should be performed on each object as it arrives from the pipeline. When all objects have been processed, the results are sent down the pipeline to the next cmdlet.

The first command in this series stops any queued tasks in a selected job that have IDs between 500 and 530 (exclusive). It uses the Get-Job cmdlet to get the jobs in the second job in the system (job [1] in a zero-based array) and the Get-Task cmdlet to get the tasks in that job. It uses the Where-Object cmdlet to select tasks with a status of “queued” and a task ID between 500 and 530. It sends the selected tasks to the Stop-Task cmdlet, which stops them.

The second command displays the tasks with task IDs between 500 and 530. The results show that the affected tasks are cancelled.

The first command in this series starts the tasks in a selected job that have IDs between 500 and 530 (exclusive) and a status of “Cancelled”. It uses the Get-Job cmdlet to get the jobs in the second job in the system (job [1] in a zero-based array) and the Get-Task cmdlet to get the tasks in that job. It uses the Where-Object cmdlet to select tasks with a status of “cancelled” and a task ID between 500 and 530. It sends the selected tasks to the Restart-Task cmdlet, which starts them.

The second command displays the tasks with task IDs between 500 and 530. The results show that the affected tasks are requeued.

The first command in this series creates a new job and stores it in the $j variable.

The second command names the job “CCPDemo”. It uses the <object>.<property> format to access the Name property of the job object in the $j variable. It uses the assignment operator (=) to assign the “CCPDemo” value to the Name property of the job object in the $j variable.

The third command uses the Format-List cmdlet to display the properties of newly-created job object as a list.

This command limits the CCPDemo job to four processors. It uses the <object>.<property> format to access the MaximumNumberOfProcessors property of the job object in the $j variable, and an assignment statement to assign a value of “4” to the property.

PS ccp:\> $j.MaximumNumberOfProcessors = 4

New Task: Creates a new task in a job.

The first command in this series uses the New-Task cmdlet to creates a new task. Then, it stores the new task in the $t1 variable.

The second command uses the <object>.<property> format to access the Name property of the new task object in the $t variable. Then, it assigns the “t1” name to the task.

The third command uses the object>.<property> format to access the CommandLine property of the task object in the $t1 variable. Then, it assigns the “t1cmd” value to the CommandLine property.

The Get-Node command actually gets an array of objects, each of which represents one node. You can use standard array notation to access the items in the array.

This command uses array notation to access the first node object in the $a variable.

PS ccp:\> $a[0]

Name Status Proc Idle —- —— —- —- HPC-DEMO-CN-11 Ready 2 2

You can use the cmdlets that come with Windows PowerShell to manipulate the CCP data.

This command uses the Select-Object cmdlet and its First parameter to select only the first two nodes returned by Get-Node. The results are stored in the $a variable.

The parentheses in this command have no effect. They are added to show that the Get-Node and Select-Object commands are completed before the result is stored in the $a variable. (The pipeline operator takes precedence over the assignment operator.)

The command uses the Select-Object cmdlet and its First parameter to select only the first three nodes returned by Get-Node. The second pipeline operator in the command sends the objects representing the three nodes to Suspend-Node, which pauses the nodes.

The second Get-Node command confirms that Suspend-Node affected only the first three nodes.

This command uses the Where-Object cmdlet to select only the paused nodes from the array that Get-Node gets. The paused nodes are sent to the Resume-Node cmdlet, which changes their status from “paused” to “ready.”

The pipeline operator sends objects down the pipeline one at a time. The Where-Object command uses the “$_.” symbol, which refers to the current object sent down the pipeline. The operation that it specifies is performed on each object as it arrives. When all objects have been processed, the results are sent to the next cmdlet.

SEE ALSO For information about individual Cmdlets, use the help alias (for the get-help Cmdlet) followed by the Cmdlet name. For example, to view information about the get-node Cmdlet, Enter the following command:

help get-node

To get a full list of Cmdlets for CCP, enter the following command:

get-command -pssnapin CCPSnapIn

To change the value of the environment set CCP_SCHEDULER, use this command: