CleanCode logo

CleanCode PowerShell Libraries v1.2.06 API: CleanCode » SqlTools » Out-DataTable





Creates a DataTable for an object.


Out-DataTable [-InputObject] <PSObject[]> [-TypeFilter <String>] [<CommonParameters>]


Creates a DataTable based on an object's properties. (Based on Chad Miller's original work--see Links section.)


-InputObject <PSObject[]>

        Specifies the objects to be converted to a DataTable.
        If an array of objects is passed, any with a type that differs 
        from the first object in the list are ignored and a warning is displayed.
        To suppress the warning, use the TypeFilter parameter to pre-filter the list to a single type.

        Required?                    true
        Position?                    1
        Default value                
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  false

-TypeFilter <String>
        Specifies a selection filter by data type name.
        If not specified, all objects are processed and those with differing types
        generate a warning message.
        If TypeFilter is specified, only those objects matching the type name are processed.

        Required?                    false
        Position?                    named
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false

        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, see 
        about_CommonParameters ( 


Object. Any object can be piped to Out-DataTable.




        Adapted from script by Marc van Orsouw see link 
        Version History 
        v1.0  - Chad Miller - Initial Release 
        v1.1  - Chad Miller - Fixed Issue with Properties 
        v1.2  - Chad Miller - Added setting column datatype by property as suggested by emp0 
        v1.3  - Chad Miller - Corrected issue with setting datatype on empty properties 
        v1.4  - Chad Miller - Corrected issue with DBNull 
        v1.5  - Chad Miller - Updated example 
        v1.6  - Chad Miller - Added column datatype logic with default to string


-------------------------- EXAMPLE 1 --------------------------
C:\PS>$dt = Get-PsDrive | Out-DataTable

This example creates a DataTable from the properties of Get-PsDrive and assigns output to the $dt variable.

-------------------------- EXAMPLE 2 --------------------------
C:\PS>$dt = Get-ChildItem | Out-DataTable -TypeFilter FileInfo

This example creates a DataTable selecting only those objects that have type FileInfo (i.e. ignoring those of type DirectoryInfo, the other object output by Get-ChildItem).


This documentation set was created with CleanCode's DocTreeGenerator.

Valid XHTML 1.0!Valid CSS!Get CleanCode at Fast, secure and Free Open Source software downloads
Copyright © 2001-2014 Michael Sorens • Contact usPrivacy Policy
Usage governed by Mozilla Public License 1.1 and CleanCode Courtesy License
CleanCode -- The Website for Clean DesignRevised 2014.12.31