Created
July 27, 2018 15:43
-
-
Save alevyinroc/cfccbc2b0adfd270c27358d8a1044ab7 to your computer and use it in GitHub Desktop.
Demos write-dbadatatable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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