Archive Page 2

The free and open source H9Labs PowerShell Cmdlets project consists of a series of PowerShell cmdlets created by the fine folks at H9Labs (that would be us), which we find useful and wanted to give back to the community. To that end, here are the H9Labs PowerShell Cmdlets!

Out-DataSet

Out-DataSet is an extremely useful and needed cmdlet. You can use it to pipe any type of data that can be formatted with the built-in cmdlet, Format-Table, into a typed Microsoft .NET System.Data.DataSet. This allows an unlimited manipulation of data that you simply cannot achieve with text globbing. This cmdlet is experimental in nature because it was achieved by reverse engineering the Format-Table cmdlet to pull the data directly from internal data structures that Microsoft does not expose via its public API. This was a necessary task in order to represent the data with 100% accuracy every single time.

Because the built-in cmdlet, Format-Table, is used to pre-process objects for a DataSet, an internal PowerShell runspace is created in order to execute the FT cmdlet. Internal PS runspace’s only load the built-in format schemas, not any other format schema files, which means that if your objects require an external format file for FT to work correctly, then you must use the Out-DataSet’s FormatSchemas parameter to pass that information in so it is loaded. By default the Out-DataSet cmdlet will attempt to load the VMware VI Toolkit’s format schema if it is available via the Registry.

Examples

Here are a few examples of using the Out-DataSet cmdlet.

Loading the Current Processes into a DataSet

PS C:\projects\h9labscmdlets> get-process | out-dataset

RemotingFormat          : Xml
SchemaSerializationMode : IncludeSchema
CaseSensitive           : False
DefaultViewManager      : {System.Data.DataViewManagerListItemTypeDescriptor}
EnforceConstraints      : True
DataSetName             : DataSet
Namespace               :
Prefix                  :
ExtendedProperties      : {}
HasErrors               : False
IsInitialized           : True
Locale                  : en-US
Site                    :
Relations               : {}
Tables                  : {}
Container               :
DesignMode              : False

You can then print out the data set’s only table to see the information that was loaded.

PS C:\projects\h9labscmdlets> (get-process | out-dataset).Tables[0] | ft

     Handles       NPM(K)        PM(K)        WS(K)       VM(M)      CPU(s)          Id ProcessName
     -------       ------        -----        -----       -----      ------          -- -----------
         102            5         1116          232          32        0.17         372 alg
         616            8         2872         3272          28      122.81         644 csrss
          89            4          900         1620          29        4.56        2336 ctfmon
        1616           81       242376        27408         855      313.03         336 devenv
        1423           72       278244        25760         724       42.92        4008 devenv
         411           10        12756         9444          71       72.75        1332 explorer
         443           16        12584        11744          72       91.58        2356 explorer
         291            8         3504         3176          51       14.78        2292 gnotify
         114           35         9948          240          92        0.69        1552 H9WebServer
          42            2          496          200          14         0.8        1780 HPZipm12
           0            0            0           16           0                       0 Idle
          32            2          612          396          28        1.05        2380 JetBrain...
         249            7         4564          376          46        0.52        3276 jucheck
          88            3          972           48          30        0.13        2168 jusched
         412           10         4016          852          41       16.67         724 lsass
         127            3          936          928          27        1.33        1640 mdm
          93           34         2188         1024          37         6.3        1748 oodag
          75            4         1464         1428          35        1.34        2324 oodtray
         263            6        33548        25084         132        1.86         776 powershell
         163            5         2396          336          44        0.33        2556 rapimgr
         349           14        72856         2352         234           5         772 Reflector
         510           31       356628       101800         572      184.61         816 Reflector
         327            8         4352         1512          51         9.3         712 services
          21            1          168           52           4        0.17         588 smss
         156            6         4776         1744          47        1.31        1400 spoolsv
         221            6         2740          512          60        0.55         900 svchost
         326           13         2028         1568          33        1.69         972 svchost
        1724           58        25968        16976         174      141.72        1056 svchost
          78            3         1344         1004          29        1.98        1104 svchost
         199            6         1700          684          36        0.63        1144 svchost
         118            4         2460          164          36        0.27        1848 svchost
        1160            0            0           44           2      666.22           4 System
        1268           48       328172       102952        1159      149.22        1604 tomcat6
         105            5         8792         6508          52       57.47        2100 TSVNCache
          23            2          564           68          15        0.22         888 vmacthlp
         210            4         1996         1784          37      536.94        1936 VMwareSe...
          33            2          836          780          29        0.39        2200 VMwareTray
         227            7        11188         5112          72       23.33        2248 VMwareUser
         141            6         1300          508          45        0.66        2456 wcescomm
         328            9         5072         2504          49        6.67         668 winlogon
         259           39        16516          848         127         1.7        2532 Xenocode...

Would You Like to Know More?

You can read more about and download the H9Labs PowerShell Cmdlets project at its SourceForge project site, http://h9labscmdlets.sourceforge.net/.


Better Late Than Never

Dang the inter webs are fast! Before I was able to get a blog post up describing the new plug-in and how to use it, the Twitter world was already alive with news of my latest creation. I suppose I should be flattered, but I do like to stay ahead of things with all the right documentation in order to reduce confusion. Well, better late than never I suppose…

A Brief Explanation

As some of you may know, I have released a new VI3 plug-in via H9Labs called the Search Bar Plug-in for VI3. The plug-in adds search capabilities to VI3 clients through an integrated search bar in the upper-left hand corner of the client. This functionality is present by default in VMware’s recently announced vSphere4, but severely lacking in VI3. I, along with my CTO, Dave McCrory (who gave me great advice on the plug-in and produced the H9Labs graphics for it), figured we would simply back port the search capabilities from vSphere4 into VI3.

The H9Labs Search Bar Plug-in for VI3 in action

The H9Labs Search Bar Plug-in for VI3 in action

Installing the Plug-in

The plug-in should be simple to install. Simply go to the Hyper9 Store and download the installer (free registration required). Because I am now working for Hyper9, you will have to create a free account to access my software. I’m sorry, but those are the breaks necessary to pay a mortgage in today’s US economy.

Once you have the installer simply double-click on it to launch the installation wizard. The only value you should have to enter is the name of the Hyper9 server you want to the plug-in to interact with. If you don’t have a Hyper9 server I highly recommend that you download one and give it a try at Hyper9.com. If you do not have or do not wish to try a Hyper9 server at this moment then you can simply leave the field blank and click next. Once the installer has completed, you may launch the VI client.

Using the Plug-in

Once the VI client has finished starting up you may notice a few additions to the interface.

A close-up of the H9Labs Search Bar Plug-in for VI3

A close-up of the H9Labs Search Bar Plug-in for VI3

For one, there is now a new button in the main toolstrip. This is the Hyper9 button that will launch the Hyper9 interface directly from within the VI client. If you did not specify a Hyper9 server during installation then this button will simply take you to the Hyper9 website.

The second addition is a little more obvious: there is now a text box located next to the VMware logo in the upper-right hand section of the VI client. Pretty cool huh? Kids, if you want to try adding components directly to the VI client, I will give you this hint. Remember, you’re working in .NET, and you can basically do whatever you want to a program running in .NET by attaching to running memory and manipulating it as you see fit. We in the biz call it gleaming the cube. Okay, we don’t really call it that. Well, okay, I have no idea what the biz is. I’m just saying, that you too can modify the .NET client, but aside from telling that it requires some serious reflection (<– HINT, HINT) on your part, I cannot give your further pointers.

VI admins can use the search bar to find items in the VI inventory by using pattern matching on names and IP addresses (for VMs and hosts). The search bar’s drop-down menu divides results into several categories.

  • Clusters
  • Datacenters
  • Datastores
  • Folders
  • Hosts
  • Networks
  • ResourcePools
  • Templates
  • VirtualMachines

You can also short-cut searches to a specific type of object by prefixing the search pattern with the following text:

  • ccr:
  • cr:
  • dc:
  • ds:
  • folder:
  • host:
  • ip:
  • net:
  • rp:
  • template:
  • vm:

All of the prefixes should be self-explanatory except for perhaps the cr: and ccr: prefixes. Those match compute resources and cluster compute resources, or as the latter is more commonly known, clusters.

One of the really cool features of the plug-in is that when you find the item you are looking for, double-click on it with your mouse or highlight it and click Enter and the VI inventory will change views to display the item. For example, if you are currently looking the the Hosts and Folders view and you click on a Datastore, the inventory will change to the Datastore view. Cool, huh?

At any time in the VI3 client a VI admin can use the key combination Ctrl-Shift-f to jump directly to the search bar. While in the search bar a user can type a search and then use the down arrow key to move into the search results and then use the Backspace or Escape keys to go back to the search box.

You can also simply strike the Enter key while typing in a search and the VI client will transition to the integrated Hyper9 interface and submit your search query to the Hyper9 server, leveraging the wondrous and magical powers of Hyper9. Additionally, you can right-click on hosts and VMs in the VI inventory tree and then click on the Hyper9 menu item to search for that item in the Hyper9 interface as well.

That’s All I Have to Say About That…

If you have any questions, check out the search bar’s support forum at the Hyper9 community portal. I will leave you with this screen cast walking you through how to use the plug-in by Hyper9’s resident genius, Zahid Ghauri.


I was working on a project recently using the Google Web Toolkit (GWT) in conjunction with the GWT wrapper (GWT-EXT) for the fabulous ExtJS Javascript library. The program’s design ran up against a road-block, however, when I realized that my application’s architecture was simply not well-suited for the type of work I was doing. The application essentially:

  1. Draws some elements on the screen
  2. Fetches data
  3. Possibly populate some of the existing elements with some of the data
  4. Possibly create new elements based on said data and possibly populate some of the new elements with some of the data

Seems simple, right? It would be except for a snag. See, since I am doing a lot of AJAX wizardry dependent upon the results of my data, some of the magic relies on DOM calculation. The problem is that I need to guarantee that my screen elements are 1) attached to the DOM and 2) visible on the screen. Of course, this presents another problem. I don’t want my elements to be visible until they are ready to be shown, but many interesting Javascript widgets that ship with ExtJS do calculations based on offsetHeight, offsetWidth, etc. — values that can only be computed if the element is visible and attached to the DOM.

My solution was simple, I would just draw the elements off-screen until they were ready to be displayed. But how would I know when the elements were finished “opening?” Enter the interface ScreenElement.java. ScreenElement is a Java interface that any widget which retrieves data and has its appearance modified based on that data should implement:

package com.lostcreations.vmm.client;

import com.google.gwt.user.client.ui.Panel;
import com.gwtext.client.core.ExtElement;

/**
 * An interface for any element drawn on the screen.
 *
 * @author akutz
 *
 */
public interface ScreenElement
{
    /**
     * Begin the data retrieval operation.
     */
    public void beginFetch();

    /**
     * Close this screen element. This method should call the following methods
     * in this order.
     *
     * <ol>
     * <li>hide()
     * </li><li>offScreen()</li>
     * </ol>
     */
    public void close();

    /**
     * Does client-side computation after the data has been flushed into the
     * element.
     */
    public void compute();

    /**
     * Draws this screen element.
     */
    public void draw();

    /**
     * Ends the data retrieval operation indicating that no errors occurred.
     */
    public void endFetch();

    /**
     * Ends the data retrieval operation with the option to specify that error
     * occurred.
     *
     * @param withErrors True to indicate errors; otherwise false.
     */
    public void endFetch(Boolean withErrors);

    /**
     * Flushes the data into the screen element.
     */
    public void flush();

    /**
     * Sets this element's visibility to hidden and its display mode to none.
     */
    public void hide();

    /**
     * Returns true if their is still data being retrieved from the server;
     * otherwise false.
     *
     * @return True if their is still data being retrieved from the server;
     *         otherwise false.
     */
    public boolean isFetching();

    /**
     * Returns true if this screen element is currently open.
     *
     * @return True if the screen element is open; otherwise false.
     */
    public boolean isOpen();

    /**
     * Moves the screen element off-screen and then sets its visibility to true.
     */
    public void offScreen();

    /**
     * Is called when the fetch operation is completed. This method should call
     * the following methods in this order:
     *
     * <ol>
     * <li>flush()</li>
     * <li>compute()</li>
     * <li>hide()</li>
     * <li>onScreen()</li>
     * <li>show()</li>
     * </ol>
     */
    public void onEndFetch();

    /**
     * Is fired when the open operation is completed.
     */
    public void onOpen();

    /**
     * Moves the screen element on-screen and then sets its visibility to false.
     */
    public void onScreen();

    /**
     * Open this screen element. This method should call the following methods
     * in this order:
     * <ol>
     * <li>offScreen()</li>
     * <li>show()</li>
     * <li>draw()</li>
     * <li>beginFetch()</li>
     * </ol>
     *
     * @param parent The panel this screen element will be added to once opened.
     */
    public void open(Panel parent);

    /**
     * Sets this element's visibility to visible and its display mode to
     * 'block'.
     */
    public void show();

    /**
     * Sets this element's visibility to visible and its display mode to a valid
     * CSS value.
     *
     * @param displayMode A valid CSS value for display mode.
     */
    public void show(String displayMode);
}

This interface guarantees that an element is ready to be shown to the client. The pattern is as follows:

  1. The element’s open(Panel parent) method is invoked where parent is the panel the element should be added to once it has finished opening.
  2. The element is created and immediately moved off-screen so that the user does not see the element.
  3. The element’s show() method is invoked to make the element visible.
  4. The element’s draw() method is invoked to draw the element’s child controls. Since the element is visible, any control that needs to do DOM calculations will be able to.
  5. The element invokes the beginFetch() method. A timer is then immediately started which checks every 50 milliseconds to see if the element has completed its fetch operation by calling the isFetching() method.
  6. Once the data retrieval has completed, the endFetch() method will be invoked. This causes the timer mentioned in the last step to cancel itself and then invoke the onEndFetch() method.
  7. The onEndFetch() method then invokes the flush() method where the data that was retrieved is acted upon. This could mean additional child controls are added to the element or simply that existing child controls have data populated.
  8. The compute() method is invoked next. This is where any DOM-related computations should take place that are dependent upon the flushed data (such as progress bars). Since the element is still visible off-screen and the data is now in place, the DOM can be updated accordingly and successfully.
  9. The element is then hidden with the hide() method in order to prepare it to be moved onto the screen.
  10. The element is moved on screen by invoking the onScreen() method, but this does not make the element visible.
  11. Next, the element is shown to the user with the show() method.
  12. Finally the onOpen() method is called setting the element’s opened state to True for any timers waiting on the element to be opened.

That’s it! It’s pretty straight-forward, and it guarantees that the elements are drawn correctly before they are shown to the user. Not only that, but it is a great way to think about how you are working with these elements. It really structures things (at least for me). The end of this post includes two classes that implement this interface (a base, abstract class and a final class) to give you an idea of how this works in the real world.

package com.lostcreations.vmm.client;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Panel;
import com.gwtext.client.core.ExtElement;
import com.gwtext.client.core.Function;
import com.gwtext.client.core.FxConfig;

/**
 * The abstract base class for views.
 *
 * @author akutz
 *
 */
public abstract class ViewImpl implements View, ScreenElement
{
    /**
     * The view's main content container.
     */
    private DivVerticalPanel viewContainer;

    /**
     * True if this view is open; otherwise false.
     */
    private boolean isOpen;

    private boolean isFetching;

    Panel parent;

    protected ViewImpl()
    {
        Log.trace("creating new " + getClassName());
        this.viewContainer = new DivVerticalPanel();
        this.viewContainer.addStyleName("view");
        hide();
        Log.trace("created new " + getClassName());
    }

    protected String getClassName()
    {
        return this.getClass().getName();
    }

    public void compute()
    {
    }

    public void close()
    {
        if (!this.isOpen) return;
        hide();
        offScreen();
    }

    public DivVerticalPanel getViewContainer()
    {
        return this.viewContainer;
    }

    public void offScreen()
    {
        ScreenElementUtil.offScreen(this.viewContainer.getElement());
    }

    public void onScreen()
    {
        ScreenElementUtil.onScreen(this.viewContainer.getElement());
    }

    public boolean isOpen()
    {
        return this.isOpen;
    }

    public void open(Panel parent)
    {
        if (this.isOpen) return;

        this.parent = parent;

        offScreen();
        parent.add(this.viewContainer);
        show();
        draw();
        beginFetch();

        // Start a timer that checks ever 50 milliseconds to see if this
        // element is finished fetching data.
        Timer t = new Timer()
        {
            @Override
            public void run()
            {
                if (!isFetching())
                {
                    Log.trace(getClassName() + " finished fetching");
                    cancel();
                    onEndFetch();
                }
                Log.trace(getClassName() + " still fetching");
            }
        };

        t.scheduleRepeating(50);
    }

    /**
     * Begin any data retrieval operations. Classes that override this method
     * must call super.beginFetch() before doing any other operations.
     */
    public void beginFetch()
    {
        this.isFetching = true;
        Log.trace(getClassName() + " begin fetch");
    }

    public void endFetch()
    {
        endFetch(false);
    }

    public void endFetch(Boolean withErrors)
    {
        this.isFetching = false;
        Log.trace(getClassName() + " end fetch");
    }

    public final boolean isFetching()
    {
        return this.isFetching;
    }

    public final ExtElement getExtEl()
    {
        return ScreenElementUtil.getExtEl(this.viewContainer.getElement());
    }

    public final void hide()
    {
        ScreenElementUtil.hide(this.viewContainer);
    }

    public void fadeIn()
    {
        ScreenElementUtil.appear(this.viewContainer);
    }

    public void fadeOut()
    {
        ScreenElementUtil.fade(this.viewContainer);
    }

    public void show(String displayMode)
    {
        ScreenElementUtil.show(this.viewContainer);
    }

    public final void show()
    {
        ScreenElementUtil.show(this.viewContainer);
    }

    public void onOpen()
    {
        this.isOpen = true;
    }

    public final void onEndFetch()
    {
        Log.trace(getClassName() + " onEndFetch started");

        flush();
        compute();
        hide();
        onScreen();

        FxConfig fcIn = new FxConfig();
        fcIn.setCallback(new Function()
        {
            public void execute()
            {
                onOpen();
            }
        });

        new ExtElement(this.viewContainer.getElement()).fadeIn(fcIn);

        Log.trace(getClassName() + " onEndFetch completed");
    }
}
package com.lostcreations.vmm.client;

import com.google.gwt.user.client.Timer;

/**
 * This application's main view.
 *
 * @author akutz
 *
 */
public class MainView extends ViewImpl
{
    final AccountPanel accountPanel = new AccountPanel();

    /**
     * Initializes a new MainView object.
     */
    public MainView()
    {
        super();
        getViewContainer().getElement().setId("mainView");
    }

    public void draw()
    {
        accountPanel.open(getViewContainer());
    }

    public void flush()
    {

    }

    @Override
    public void beginFetch()
    {
        super.beginFetch();

        // Do not end the fetch until the account panel has been completed
        // its open operation.
        Timer t = new Timer()
        {
            @Override
            public void run()
            {
                if (accountPanel.isOpen())
                {
                    cancel();
                    endFetch();
                }
            }
        };

        t.scheduleRepeating(50);
    }
}

For those of you using Eclipse, Gwt-Rocket, and Java 1.5, you may be getting errors when launching your GWT app in hosted mode that look like this:

[java] [ERROR] Line 354: The constructor StackTraceElement(String, String, String, int) is undefined

The solution as documented here is to make sure that your Rocket jars are loaded before the GWT jars.


I have been paranoid about my data recently, and even though I have a fairly nice backup system at home, I really wanted to get my data off-site. I have a Dreamhost account, and therefore 50G of backup space and each additional G only cost .10 USD. Since I use a central BackupPC server at home to connect to my other servers and my and my wife’s laptops, I am able to leverage BackupPC’s archive feature to create archives of my latest backup sets. These archives are created using tar and b|gunzip2?. However, the archives that BackupPC creates are not protected in any way, and I do not want to store my files on Dreamhost’s servers without somehow password protecting them or encrypting them.

Enter 7zip. 7zip supports protecting archives with a password, and if we use a long (20+ characters) passphrase, the archives are as protected as can be. However, 7zip does not make a good backup utility for Linux because it does not preserve the file permissions, so we still need to create a tar archive prior to using 7zip to compress, and protect the archive.

You may be asking why we don’t simply use GPG or OpenSSL to encrypt the tar archive? We could, but we would still need to compress the archive, and 7zip does a better job than either gzip or bunzip2 does, so why not just kill two birds with one stone by protecting and compressing all in one fell swoop?

So, the goal is to create a BackupPC archive of a host first using tar to preserve the Linux file permissions of the files being archived, and then using 7zip to compress and protect the files. Easy as pie. Simply type the following:


su backuppc -c "/usr/share/backuppc/bin/BackupPC_tarCreate -t -h $HOST -n -1 -s \* . | 7z a -p\"$PASS\" -v$SPLT -si /home/archive/$HOST-$(date +%Y-%m-%d).tar.7z"

The above command assumes that the environment variables are set:

  • HOST – The name of the host you want to archive.
  • PASS – The password to use to protect the 7zip archive file.
  • SPLT – The number of blocks to split the archive volume on. This can be 1K, 2M, 3G, etc.

Assuming that the name of my host is ‘build’, and I specified a volume split of 3G, then the above command would produce the following compressed, protected, archive file: build-2008-12-23.tar.7z.001.


StyleCopCmd provides both a command-line interface and NAnt task for Microsoft’s StyleCop source analysis tool. Not only that, but StyleCopCmd produces beautiful HTML reports that can be integrated into an automated build system such as JetBrains TeamCity 4.0 EAP.

StyleCopReport - Expanded

An expanded StyleCopCmd report

You can download both the binary and source packages, as well as read more about StyleCopCmd at http://stylecopcmd.sourceforge.net/.


I have been playing around with the new data access layer, the Entity Data Model (EDM), from Microsoft. However, I quickly learned that the EDMX files that Visual Studio creates for you when you create a data model are unique to Visual Studio. In fact, an EDM is made up of three files that are known as metadata artifacts:

  • Conceptual Model – CSDL
  • Storage Model – SSDL
  • Mappings Model – MSL

Continue reading ‘NAnt and Processing EDMX Files’


I just wanted to let everyone know that I will be writing a series of articles soon on how I managed to take the StyleCop 4.3 SDK, NAnt 0.86 Beta 1, and Team City 4.0 and create the following screen shot:

StyleCop 4.3 integrated into Team City 4.0

StyleCop 4.3 integrated into Team City 4.0


Including the infamous Eric Sloof, who recorded it for me! Check it out:


When I read about the Maryland Mayor whose two dogs were shot and killed by police after a truly horrific drug-bust gone bad I have to wonder: “Do the police have too much power?” This type of story really makes me stop and think that something in this country has gone horribly wrong — when innocent people are set up by police, then attacked by police, then forced to witness the execution of their loved ones by police, what the hell are the police good for?

My sympathies to the mayor, his wife, and mother-in-law. To the men responsible for the deaths of those animals — may you live forever.