software development

Introducing H9Labs PowerShell Cmdlets – Out-DataSet

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/.

Advertisements

One thought on “Introducing H9Labs PowerShell Cmdlets – Out-DataSet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s