Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created April 21, 2020 20:02
Show Gist options
  • Save aadennis/0d700c0678c793c2a8a2fa63b7aaf2d7 to your computer and use it in GitHub Desktop.
Save aadennis/0d700c0678c793c2a8a2fa63b7aaf2d7 to your computer and use it in GitHub Desktop.
# Show the content of a set of tables on a given database
function Get-TableSet($database, $tableSet) {
$tableSet | ForEach-Object {
$table = $_
$query = "select '$table' as [Table-$table], * from [$database].[dbo].[$table] "
Write-Host "Running [$query]."
Invoke-Sqlcmd -ServerInstance localhost -U sa -P TheDemo -Query $query -Verbose |
Out-GridView -Title "$database.$table "
}
}
$database = "aa_somedb"
$tableset = "things","things2"
Get-TableSet $database $tableset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment