Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out ConvertTo-DbaDataTable on GitHub.
Want to see the Bill Of Health for this command? Check out ConvertTo-DbaDataTable.
Creates a DataTable for an object.
Creates a DataTable based on an object's properties. This allows you to easily write to SQL Server tables.
Thanks to Chad Miller, this is based on his script. https://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd
If the attempt to convert to data table fails, try the -Raw parameter for less accurate datatype detection.
ConvertTo-DbaDataTable
[-InputObject] <PSObject[]>
[-TimeSpanType <String>]
[-SizeType <String>]
[-IgnoreNull]
[-Raw]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-Service | ConvertTo-DbaDataTable
Creates a DataTable from the output of Get-Service.
PS C:\> ConvertTo-DbaDataTable -InputObject $csv.cheesetypes
Creates a DataTable from the CSV object $csv.cheesetypes.
PS C:\> $dblist | ConvertTo-DbaDataTable
Creates a DataTable from the $dblist object passed in via pipeline.
PS C:\> Get-Process | ConvertTo-DbaDataTable -TimeSpanType TotalSeconds
Creates a DataTable with the running processes and converts any TimeSpan property to TotalSeconds.
The object to transform into a DataTable.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Specifies the type to convert TimeSpan objects into. Default is 'TotalMilliseconds'. Valid options are: 'Ticks', 'TotalDays', 'TotalHours', 'TotalMinutes', 'TotalSeconds', 'TotalMilliseconds', and
'String'.
Alias | |
Required | False |
Pipeline | false |
Default Value | TotalMilliseconds |
Accepted Values | Ticks,TotalDays,TotalHours,TotalMinutes,TotalSeconds,TotalMilliseconds,String |
Specifies the type to convert DbaSize objects to. Default is 'Int64'. Valid options are 'Int32', 'Int64', and 'String'.
Alias | |
Required | False |
Pipeline | false |
Default Value | Int64 |
Accepted Values | Int64,Int32,String |
If this switch is enabled, objects with null values will be ignored (empty rows will be added by default).
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, the DataTable will be created with strings. No attempt will be made to parse/determine data types.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |