Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<_locDefinition xmlns="urn:locstudio">
<_locDefault _loc="locNone" />
<_locTag _loc="locData">Title</_locTag>
<_locTag _loc="locData">Description</_locTag>
<_locTag _loc="locData">Author</_locTag>
<_locTag _loc="locData">ToolTip</_locTag>
</_locDefinition>
<CodeSnippet Format="1.0.0">
DECLARE @Debug BIT= 1;
DECLARE @ImSure BIT= 1;
IF(@Debug = 1)
BEGIN
PRINT @MyQuery;
END;
IF(@ImSure = 1)
BEGIN
EXEC sp_executesql @MyQuery;
@alevyinroc
alevyinroc / QueryParameters.ps1
Created July 27, 2018 15:36
Demonstrate parameterized queries
import-module dbatools;
$MyQuery = @"
select * from sys.databases where [name] = @DBName
"@;
$Params = @{"DBName" = "model"};
Invoke-DbaSqlQuery -SqlInstance YOURSERVER -Query $MyQuery -SqlParameters $Params;
remove-module dbatools;
@alevyinroc
alevyinroc / DemoWrite-DbaDataTable.ps1
Created July 27, 2018 15:43
Demos write-dbadatatable
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;
@alevyinroc
alevyinroc / copy-table.ps1
Last active November 14, 2018 16:58
Copies a database table including definition
$SourceServer = "MYSOURCE";
$SourceDB = "MySourceDB";
$DestDB = "MyDestDB";
$TableName = "MyTable";
# Get the table definition from the source
$tablescript = Get-DbaDbTable -ServerInstance $SourceServer -Database $SourceDB -Table $TableName | Export-DbaScript -Passthru;
# Run the script to create the table in the destination
Invoke-DbaQuery -Query $tablescript -ServerInstance $SourceServer -Database $DestDB;
@alevyinroc
alevyinroc / Install-frk1.ps1
Created December 5, 2018 13:15
Install-frk1.ps1
Invoke-WebRequest -Uri http://firstresponderkit.org | Select-Object -ExpandProperty Headers
Key Value
--- -----
x-amz-id-2 {QtTLMVw5QobGd/xlueEIY44Ech2va1ZKALhaMrY9f/yI0fBHvAoA6KwGUa5jTQxPF5fF85tuYws=}
x-amz-request-id {86A4E2A10548CA53}
Date {Sat, 03 Jun 2017 16:14:47 GMT}
ETag {&quot;4ff7c8b410c399d5b18e2ab05bbfce22&quot;}
Server {AmazonS3}
@alevyinroc
alevyinroc / Install-frk2.html
Created December 5, 2018 13:18
Install-frk2.html
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/master">
<script type="text/javascript">
window.location.href = "https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/master"
</script>
<title>Page Redirection</title>
@alevyinroc
alevyinroc / install-frk3.ps1
Created December 5, 2018 13:19
install-frk3.ps1
(Invoke-WebRequest -Uri http://firstresponderkit.org).Links |Format-List
outerHTML : <a href="https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/master">head over here.</a>
tagName : A
href : https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/master
import-module poshrsjob;
$PollingInterval = 5;
$CompletedThreads = 0;
$Status = Get-RSJob | Group-Object -Property State;
$TotalThreads = ($Status|Select-Object -ExpandProperty Count | Measure-Object -Sum).Sum;
while ($CompletedThreads -lt $TotalThreads) {
$CurrentJobs = Get-RSJob;
$CurrentJobs.Where( {$PSItem.State -eq "Completed"}) | Receive-RSJob | Out-Null;
$CurrentJobs.Where( {$PSItem.State -eq "Completed"}) | Remove-RSJob | Out-Null;
$Status = $CurrentJobs|Group-Object -Property State;
import-module poshrsjob, PSFramework;
$DownloadDir = "e:\tmp\poshrsjob";
$MaxJobs = 3;
$LogFile = Join-Path -path $DownloadDir -ChildPath "Demo-$(Get-date -f 'yyyyMMddHHmmss').txt";
#Set-PSFLoggingProvider -name logfile -Enabled $true -filepath $LogFile;
Set-PSFLoggingProvider -name filesystem -Enabled $true -logpath $DownloadDir;
foreach ($i in 1..6) {
Start-RSJob -Throttle $MaxJobs -Batch "Demo" -argumentlist $i, $DownloadDir -ModulesToImport PSFramework -ScriptBlock {
param($JobNum, $OutputDir)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;