Last active
December 16, 2015 03:38
-
-
Save sergejusb/5370816 to your computer and use it in GitHub Desktop.
Basic Power-Shell cmdlets to work with SQL Server (via sqlcmd.exe)
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
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
# SQL Server functions | |
function Execute-Sql($sql, $username, $password, $file) { | |
Write-Host -ForegroundColor Cyan "Executing $file on $sql with user $username" | |
& sqlcmd -S $sql -U $username -P $password -i $file | |
} | |
function Execute-SqlDir($sql, $username, $password, $dir) { | |
Get-ChildItem $dir | Select-Object FullName | foreach { | |
Write-Host -ForegroundColor Cyan "Executing $_.FullName on $sql with user $username" | |
Execute-Sql $sql $username $password $_.FullName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment