Skip to content

Instantly share code, notes, and snippets.

@alevyinroc
Created July 27, 2018 15:43
Show Gist options
  • Select an option

  • Save alevyinroc/cfccbc2b0adfd270c27358d8a1044ab7 to your computer and use it in GitHub Desktop.

Select an option

Save alevyinroc/cfccbc2b0adfd270c27358d8a1044ab7 to your computer and use it in GitHub Desktop.
Demos write-dbadatatable
import-module dbatools,ImportExcel;
$MyQuery = @"
select * from sys.databases where [name] = @DBName
"@;
$Params = @{"DBName" = "model"};
Invoke-DbaSqlQuery -SqlInstance YOURSERVER -Query $MyQuery -SqlParameters $Params | export-excel -Path e:\tmp\myfile.xlsx;
$MyData = Import-Excel -path e:\tmp\myfile.xlsx;
$MyData|ConvertTo-DbaDataTable|Write-DbaDataTable -SqlInstance YOURSERVER -database Demo -Table MyTable -Schema dbo -AutoCreateTable;
Remove-Item e:\tmp\myfile.xlsx;
Invoke-DbaSqlQuery -SqlInstance YOURSERVER -Query "select * from demo.dbo.mytable";
remove-module dbatools,ImportExcel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment