VMware

April 28, 2008

More Fun With PowerShell Mashups

A few weeks ago I blogged about using PowerGadgets to create custom dashboards to monitor Virtual Infrastructure performance. It was a great example of how easy it is to combine different domains within PowerShell.

Today I want to talk about a slightly different type of monitoring: alarms. VirtualCenter provides a very sophisticated alarm generation system. The problem is, what if you're not in VirtualCenter watching the alarm tab? Wouldn't it be better if alarms would reach out and find you wherever you are?

Again, PowerShell provides a very easy solution, due to the ease in which it combines different domains. The VI Toolkit (for Windows) makes it easy to get alarms from VirtualCenter, and /n software's NetCmdlets makes it really easy to send instant messages. Combine the two and you have a monitoring solution that just about anyone can write and customize.

First, a bit of background: NetCmdlets provides a lot of really useful functionality to PowerShell, including sending email, logging into servers via SSH, downloading files via FTP and a lot more. As usual, the cmdlets come with a very easy syntax, built in documentation and are very easy to learn and use.

Taking that, and combining it with the VI Toolkit (for Windows), I wrote a script that monitors VirtualCenter for alarms and, when it sees new alarms, sends an IM using NetCmdlets. (Note that when you run the script, you are prompted for a login. This login is the login to your Jabber server, not to VirtualCenter.) NetCmdlets currently only supports Jabber as an IM protocol, but more protocols may be added in the future. If IM is not your thing, it's also really easy to get NetCmdlets to send email instead.

Here's an example of the results:

Imalarm

The best thing about this is it only took me a couple of hours to put together, and that was mostly due to alarms not being easy enough to access from the current version of the Toolkit (we'll fix this in a later release, but the script above also contains a script cmdlet that returns all alarms.) Developing a solution like this using other technologies would have taken substantially longer, and wouldn't have been as easy to customize when they were complete. This, to me, is the real power of PowerShell.

So, if you haven't tried the VI Toolkit (for Windows) there's no reason you shouldn't download it today.


April 25, 2008

Changing CPU and Memory Allocations For All VMs

We here at VMware often get requests by people who are trying to tweak the default resource allocations that VMs have. This post shows you how easy it is to automate configuring and changing resource allocations is when using PowerShell.

First, a bit of background information. Each VM has a certain level of CPU and memory shares. In addition these levels may be limited or unlimited. Even further, a VM can have CPU or memory reservations, which means the VM will always have at least this minimal level of resources available to it. When shares are unlimited, a VM may receive more resources than its share allocation, provided these resources are not being used by some other VM.

By default, a VM gets normal CPU and memory shares with no reservation and no limit. This is a sensible default, but many times you want to tune this to improve performance for some applications.

This first example shows you how to set all VMs in your entire Virtual Infrastructure to high CPU shares and no limit.

Get-VM | % {Get-View $_.ID} | 
    % {$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
        $spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
        $spec.cpuAllocation.Shares = New-Object VMware.Vim.SharesInfo;
        $spec.cpuAllocation.Shares.Level = "high";
        $spec.cpuAllocation.Limit = -1;
        Get-View($_.ReconfigVM_Task($spec))}

This script works whether you have 1 VM or 1,000 VMs. The next example shows how to set a VM's memory allocation to normal, with no limit, and ensure that each VM has at least 1 GB of memory.

Get-VM | % {Get-View $_.ID} |
    % {$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
        $spec.memoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
        $spec.memoryAllocation.Shares = New-Object VMware.Vim.SharesInfo;
        $spec.memoryAllocation.Shares.Level = "normal";
        $spec.memoryAllocation.Limit = -1;
        $spec.memoryAllocation.Reservation = 1024;
        Get-View($_.ReconfigVM_Task($spec))}

Chances are these are not quite the policies you're looking for, but you easily determine what values you want by referring to the VMware API Reference Guide.

This is extremely powerful, but it's even more so when you consider that you can combine it with cmdlets like

Get-ResourcePool

and

Get-Folder

to select exactly the VMs you want to modify. For example, using

Get-ResourcePool

you could very easily set all VMs in one resource pool to have CPU resources set to high and all VMs in another resource pool to have CPU resources set to low.

This is just one of the great things you can do when you manage VMware with PowerShell, so if you haven't looked at it yet you should definately download the VI Toolkit (for Windows) Beta.


April 21, 2008

You can manage VMware Server with PowerShell too.

Blogger John Tuffin has made an entry about his experiments managing VMware Server 2.0 Beta with PowerShell. To summarize, you can manage VMware Server with PowerShell, in much the same way you manage VMware ESX.

Thngs that will work include:

  • Listing, creating and deleting VMs.
  • Starting, stopping and resetting VMs.
  • Creating snapshot of VMs.

Things that won't work include things that VMware ESX supports but VMware Server doesn't. This is a pretty long list, but some highlight include:

  • You can't create resource pools in VMware Server.
  • You can't utilize advanced networking options such as virtual switches in VMware Server.
  • You can't VMotion VMs between VMware Server instances.

Still, if you don't have access to ESX this is a great way to find out how easy it is to manage VMware using PowerShell. Not only that, but if you do decide to upgrade to ESX to unlock some of these advanced features, the scripts you write against VMware Server will work against VMware ESX with little or no modification.


April 04, 2008

Manage VMware with PowerGUI

If you haven't seen it yet, PowerGUI is a great tool for running Windows PowerShell, and we find it to be one of the most popular PowerShell tools out there. Many of our users have anticipated a VMware PowerGUI plugin, and I'm happy to say that the wait is over.

The PowerGUI VMware PowerPack has lots of great features, including the ability to manage your ESX Hosts and VMs, as well as doing bulk operations. In my opinion, PowerGUI's best feature is that as you interact with PowerGUI, it generates PowerShell code as you go. You can take this code and re-run it later or you can parameterize it and turn it into a script. This is especially great if you're not a hard-core scripter, or if you aren't very familiar with PowerShell.

Either way, whether you're a novice or an expert, this is not a tool to be missed. Congratulations to Dmitry and team from Quest Software!


April 02, 2008

Monitoring With PowerGadgets

While I wouldn't go so far as to say that PowerGadgets is the greatest thing in the history of history, it is easily my favorite tool for Windows PowerShell, because of how easily it can be integrated with the VI Toolkit (for Windows) to create some great ways to monitor Virtual Infrastructure.

Getting insight into your entire Virtual Infrastructure

Currently it is not very easy to get an overall picture of your VMware Virtual Infrastructure using the VI Client. The VI Client comes with a number of nice charting tools, but for the most part they focus on one object at a time -- a single VM, a single resource pool or a single host. How can we get a picture of the overall status of our Virtual Infrastructure?

The VI Toolkit (for Windows) includes a cmdlet called Get-Stat, which gives you raw access to the performance statistics of VMware objects. When we combine that with the Toolkit's ability to easily retreive all of a certain type of object, it becomes easy to start making reports that cover the entire datacenter.

Here are two examples that illustrate the point. The first example, cpu.ps1 , creates a graph that shows us the average CPU utilization of all ESX hosts under management. (Note that if you want to run the script against your Virtual Infrastructure you will need to log in using the Get-VC cmdlet first.) Here's a sample that I ran against my Infrastructure:

Cpu_3

In the same vein, memory.ps1 shows us the average memory utilization across all our hosts. Here's the output I got when I ran against my systems:

Memory

Monitor All The Time

Another nice feature of PowerGadgets is the ability to publish a gadget as a Vista Sidebar. With this feature you could easily take the examples above and have a pervasive and continuously-updated view of the health of your Virtual Infrastructure, whether you are logged in through VI Client or not.

PowerGadgets: Worth the price?

PowerGadgets is not a free tool, so you'll have to decide for yourself whether its benefits cover the costs. If monitoring your Virtual Infrastructure is important to you, you should at least download the trial and try it out, I think you'll find that with the VI Toolkit (for Windows) and PowerGadgets it's pretty easy to develop a gadget that monitors the things that are most important to you. If you've got feedback, or need a bit of help getting started, please share your feedback with us in the VI Toolkit (for Windows) Community.


March 14, 2008

We Are Beta

I won't speculate on whether PowerShell fanatics are more or less likely to be sitting in front of their computers on a Friday night like I am, but regardless of when you read this post, if you use VMware ESX or VMware VirtualCenter, you should download our VI Toolkit (for Windows) Beta and give it a try.

Some of the cool things you might want to try for yourself:

  • Snapshot all of your virtual machines at once with a script like:   
    Get-VM | % { New-Snapshot -VM $_ -Name ($_.name + "-current") }
  • Automate long-running tasks like cloning using a script like:   
    foreach ($i in 1..30) { Get-Template "My Template" |
         New-VM -Name "Clone $i" }
  • Disconnect connected CD-ROM drives (to enable VMware VMotion, for example) using a script like:   
    Get-VM | Get-CDDrive |                                         
         ? { $_.ConnectionState.Connected -eq "true" } |
         Set-CDDrive -Connected:$false -Confirm:$false

In total there are 102 PowerShell cmdlets in the Beta that cover all aspects of Virtual Infrastructure management. The most important thing is that you can now easily write scripts, tailor made to your problems, that save you time and frustration, whether that means saving you 10 clicks or 100.

Once you've had a chance to kick the proverbial tires, don't forget to visit our Community Page to give your feedback or to talk with other Beta testers.

Last but not least, congratulations to the VI Toolkit (for Windows) team for all your hard work on this release!


March 07, 2008

Hope you enjoyed the PowerShell lab at VMworld Europe.

We here on the VI Toolkit (for Windows) team know just how exciting PowerShell is, but sometimes we're surprised to learn just how many people agree. Our PowerShell lab at VMworld Europe was attended by over 250 students. What surprised me most though, was that we noticed at least 3 different people working on the PowerShell lab for over 3 hours each. Considering all the great sessions and other labs offered at VMworld Europe, this is really a testament to how important PowerShell is going to be for system management in the coming years.

For most people this was the first time they had even seen our PowerShell cmdlets, but it was clear from the feedback we received that people immediately recognize how useful this will be and can't wait to get their hands on our upcoming Beta.

When we were designing the lab manual we intentionally made it pretty much impossible to do all 20 problems during the lab. The reasoning was two-fold: First to give you a flavor of all the things you can do with the VI Toolkit (for Windows), and second so that the lab manual would be advanced enough to have practical examples that you could build on as you begin to develop your own PowerShell scripts to manage VMware.

So if you've been looking for the manual, or if you didn't manage to make it to VMworld Europe, you should still be able to get a lot of value out of the VMworld Europe 2008 Automating VMware with PowerShell Lab Manual.

Now, about that Beta I mentioned above: The VI Toolkit (for Windows) will Beta this month, so you don't have very much longer to wait. If you still feel like you can't wait, you can always email vi_tk_4win-admin@vmware.com and request our technology preview. Either way, stay tuned for our upcoming Beta announcement!


November 29, 2007

Go get PowerGUI

If you use PowerShell at all and you haven't at least tried out PowerGUI, you're missing out. It's a great product. Think of it as an administrator's Swiss Army knife. And now think of being able to easily snap new tools into that knife, have them work with each other, and customize them to your liking. Fantastic.

The most recent release raises the bar even higher. Sometime back, they added a very nice standalone (and integrated) script editor. Now that editor includes a debugger. Set breakpoints. Inspect variables. Step through the script. And it's free. If you do any PowerShell scripting at all and you haven't tried this out, go get it now.


Antonio Dias


FullArmor Workflow Studio supporting VMware's PowerShell interface

Beta 1 of FullArmor Workflow Studio 1.1 includes support for our PowerShell cmdlets. Workflow Studio lets you combine PowerShell automation with the power of workflows. Those of you who saw FullArmor's Danny Kim demo the integration during our VMworld talk know just how powerful this is. Sorry, you can't actually see the demo in the PPT but you can see Danny demo a different application of the same product. FullArmor's done a nice job - PowerShell and workflow really is like combining chocolate and peanut butter. It's compelling enough that even before this beta of version 1.1 with specific support for VMware integration, some users were figuring it out on their own.

Note that you need to get an early access copy of our cmdlets before you can use them with Workflow Studio 1.1.

Antonio Dias


October 21, 2007

PowerShell GUIs

The PowerShell community has quite a few UI-driven or UI-friendly tools that work nicely with custom scripts. Examples include PowerGUI, PowerGadgets and Workflow Studio.

In that spirit, I sometimes want an ad hoc UI for some of my management activities. The attached script lets me take data and wrap it in a super-simple UI. At the top, I have a multi-column listview showing the data. At the bottom, I can have buttons with scriptblocks attached to them to act on the selected rows. Simple stuff but useful. And quite general-purpose.

Here are a couple of usage examples. I showed a variation on this during my VMworld talk this year:

out-form -title "Disconnect Devices From..." `
              -data (get-vm) -columnNames ("VM", "Floppy Count", "CD Count") `
              -columnProperties ("Name", "FloppyDrives.Count", "CDDrives.Count") `
              -actions @{"Disconnect" = {$_ | get-cddrive | set-cddrive -nomedia `
                               -confirm:$false; $_ | get-floppydrive | set-floppydrive -nomedia `
                               -confirm:$false;}}

This gives me a list of VMs along with the number of floppy and CD drives for each. I select one or more, push the "Disconnect" button, and the floppy and CD devices are disconnected. With a little PowerShell command-line (and a little bit of scripting backing it), we have a custom application. Now take that command, drop it in a .ps1 file alongside the out-form script and we have a packaged, redistributable application. Cool. :)

Unless you've got an early access copy of our PowerShell cmdlets, you can't try the example above yet. But here's an example you can try:

out-form -title "Services" -data (get-service) `
              -columnNames ("Name", "Status") `
              -columnProperties ("DisplayName", "Status") `
              -actions @{"Start" = {$_.start()}; "Stop" = {$_.stop()};}

  Services_2

This obviously isn't the most interesting use case. After all, Windows already has a service manager. The interesting uses will come from things you do in your environment. For me, that's virtualization management, thus the example above. If you think this might be useful, download the script and try wrapping a UI around something you manage. Use it yourself. Hand your newly-created app to a coworker. If you find this useful, I'd love to hear about how you use or improve it.

Here's the script: 

Download out-form.ps1

Hopefully the parameters are self-explanatory. Here's a quick summary of each just in case:

1. title - title string to display

2. data - the objects providing the information to render

3. columnProperties - the properties of the data to display, one per column

4. columnNames - name to give each column. If not specified, the property names will be used (columnProperties). If specified, columnNames must be the same size as columnProperties

5. actions - an associative array mapping names to scriptblocks. Each name string will have its own button with the accompanying scriptblock linked to its click event. If not specified, no buttons will appear.

Antonio Dias