Skip to content

Instantly share code, notes, and snippets.

# 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 "
}
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.
-- =============================================
# 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
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
# 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 (
var WeightConstants = {
POUNDS_PER_KILO: 2.20462,
POUNDS_PER_STONE:14
};
// Convert Kilos to pounds
function KgToPounds(kilos) {
return kilos * WeightConstants.POUNDS_PER_KILO;
}
var WeightConstants = {
POUNDS_PER_KILO: 2.20462,
POUNDS_PER_STONE:14
};
// Convert Kilos to pounds
function KgToPounds(kilos) {
return kilos * WeightConstants.POUNDS_PER_KILO;
}
@aadennis
aadennis / Open-WordDocs.ps1
Created January 15, 2020 18:11
The specifics differ depending on the app. Originally, this was so I could cache OneNote documents (Onenote.exe /r)
$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"
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
$funcVars = @(
"name='john'",
"age=22"
)
$dbServer = "localhost"
$dbPrefix = "AA_"
$dbName = "SomeDb"
$inputFile = "$PSScriptRoot\x.sql"
$database = "$($dbPrefix)$($dbName)"