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


Out-DbaDataTable

Creates a DataTable based on an objects properties. This allows you to easily write to SQL Server tables.

Thanks to Chad Miller, this script is mostly him with a couple fixes by Brandon Abshire.

Screenshots

Examples

To easily keep track of database space by piping the results of the command to Out-DbaDataTable which is used to Write-DbaDataTable

Get-DbaDatabaseFreespace -SqlServer $instance -IncludeSystemDBs | Out-DbaDataTable | Write-DbaDataTable -SqlServer $instance -Table tempdb.dbo.DiskSpaceExample -AutoCreateTable

To create a $datatable based off of the output of Get-Service

Get-Service | Out-DbaDataTable

To create a DataTable from the CSV object, $csv.cheesetypes

Out-DbaDataTable -InputObject $csv.cheesetypes

This is similar to above but $dbalist gets piped in

$dblist | Out-DbaDataTable

Get-Help

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

Source Code

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

Related commands