This file contains 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
# 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 " | |
} |
This file contains 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
use a_db1 | |
go | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
-- ============================================= | |
-- Description: Show the use of a simple out , | |
-- mainly for demoing calling from PowerShell. | |
-- ============================================= |
This file contains 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
# CREATE PROCEDURE DemoSp | |
# -- Add the parameters for the stored procedure here | |
# @in int, | |
# @out int out | |
# AS | |
# BEGIN | |
# SET NOCOUNT ON; | |
# select @out = @in * 2; | |
# SELECT @in, @out |
This file contains 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
function Get-DockerHost() { | |
$versionOutput = $(docker version) | |
$dockerHost = $null | |
if ($versionOutput -match "linux"){ | |
$dockerHost = "Linux" | |
} else { | |
$dockerHost = "Windows" } | |
$msg = "Currently running as a [$dockerHost] host" | |
Write-Host $msg -ForegroundColor White -BackgroundColor Blue | |
return $dockerHost |
This file contains 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
# credit: https://virtuallysober.com/2018/05/30/connecting-to-microsoft-sql-databases-using-powershell-invoke-sqlcmd/ | |
$ServerInstance = "aardvark" | |
$SQLUser = "sa" | |
$SQLPassword = "thedemo" | |
Import-Module SqlServer | |
$dbCheck = " | |
with userDatabaseSet as ( |
This file contains 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
var WeightConstants = { | |
POUNDS_PER_KILO: 2.20462, | |
POUNDS_PER_STONE:14 | |
}; | |
// Convert Kilos to pounds | |
function KgToPounds(kilos) { | |
return kilos * WeightConstants.POUNDS_PER_KILO; | |
} |
This file contains 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
var WeightConstants = { | |
POUNDS_PER_KILO: 2.20462, | |
POUNDS_PER_STONE:14 | |
}; | |
// Convert Kilos to pounds | |
function KgToPounds(kilos) { | |
return kilos * WeightConstants.POUNDS_PER_KILO; | |
} |
This file contains 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
$root = "C:\OneDrive\data" | |
$WordExe = "C:\Program Files (x86)\Microsoft Office\root\Office16\winword.exe" | |
cd $root | |
$dir = gci -r *.docx | |
$dir | |
$dir | % { | |
$note = $_ | |
$fn = $note.FullName | |
"Currently on $fn" |
This file contains 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
set NOCOUNT ON; | |
drop table things; | |
go | |
create table things ([name] NVARCHAR(50), age INT); | |
go | |
insert into things ([name], age) values ($(name), $(age)); | |
GO | |
This file contains 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
$funcVars = @( | |
"name='john'", | |
"age=22" | |
) | |
$dbServer = "localhost" | |
$dbPrefix = "AA_" | |
$dbName = "SomeDb" | |
$inputFile = "$PSScriptRoot\x.sql" | |
$database = "$($dbPrefix)$($dbName)" |