dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


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

If the attempt to convert to datatable fails, try the -Raw parameter for less accurate datatype detection.




Creates a DataTable from the output of Get-Service.

Get-Service | ConvertTo-DbaDataTable

Creates a DataTable from the CSV object $csv.cheesetypes.

ConvertTo-DbaDataTable -InputObject $csv.cheesetypes

Creates a DataTable from the $dblist object passed in via pipeline.

$dblist | ConvertTo-DbaDataTable

Creates a DataTable with the running processes and converts any TimeSpan property to TotalSeconds.

Get-Process | ConvertTo-DbaDataTable -TimeSpanType TotalSeconds


This command was created by Chrissy LeMaire. You can find Chrissy on Twitter.


From PowerShell, execute Get-Help ConvertTo-DbaDataTable -Detailed for more information on this function.

Source Code

Want to see the source code? View ConvertTo-DbaDataTable.ps1 on GitHub

Related commands