Skip to content

Instantly share code, notes, and snippets.

View SQLDBAWithABeard's full-sized avatar
🦄
Generally bearding

Rob Sewell SQLDBAWithABeard

🦄
Generally bearding
View GitHub Profile
@SQLDBAWithABeard
SQLDBAWithABeard / Setting services
Created September 30, 2018 06:29
Setting services
$vms.ForEach{
Write-Output "Looking at VM $psitem"
# Get the Engine Services
$EngineServices = Get-DbaService -ComputerName $psitem -Type Engine
# Loop through the engine services
$EngineServices.ForEach{
$ComputerName = $psitem.ComputerName
$Name = $Psitem.ServiceName
$InstanceName = $psitem.InstanceName
@SQLDBAWithABeard
SQLDBAWithABeard / testing examples code
Created September 30, 2018 07:13
testiong examples code
$Function = 'Get-DbcCheck'
Describe "$Function" {
Context "Checking $Function Examples" {
$Examples = Get-Help $Function -Examples
foreach ($examplecode in $Examples.examples.example.Code) {
It "Example Code $examplecode should not throw" {
{$examplecode} | Should -Not -Throw
}
@SQLDBAWithABeard
SQLDBAWithABeard / Invoke-SqlFailoverDetection
Last active October 15, 2021 14:47
Invoke-SqlFailoverDetection
<#
.SYNOPSIS
Downloads the Failover Detection Utility from the Tiger Team GitHub repo
https://github.com/Microsoft/tigertoolbox/tree/master/Always-On/FailoverDetection,
creates the configuration json and gathers all the required data
.DESCRIPTION
Downloads the Failover Detection Utility from the tiger teams GitHub Repo,
https://github.com/Microsoft/tigertoolbox/tree/master/Always-On/FailoverDetection
creates the configuration json dynamically depending on the SQL Instance
@SQLDBAWithABeard
SQLDBAWithABeard / docker-compose.yml
Created January 19, 2019 16:36
docker-compose.yml
version: '3.7'
services:
sql2012:
image: dbafromthecold/sqlserver2012dev:sp4
ports:
- "15589:1433"
environment:
SA_PASSWORD: "Password0!"
ACCEPT_EULA: "Y"
@SQLDBAWithABeard
SQLDBAWithABeard / profile.ps1
Last active November 30, 2020 18:32
Prompt
[System.Console]::OutputEncoding = [System.Text.Encoding]::ASCII
# borrowing heavily from https://dbatools.io/prompt but formatting the execution time without using the DbaTimeSpanPretty C# type
function Prompt {
if($PSVersionTable.PSVersion.Major -eq 6){
Write-Host (Get-Date -Format "PS 6 ") -ForegroundColor Yellow -NoNewline
}
elseif($PSVersionTable.PSVersion.Major -eq 5){
Write-Host (Get-Date -Format "PS 5 ") -ForegroundColor Yellow -NoNewline
}
elseif($PSVersionTable.PSVersion.Major -eq 7){
@SQLDBAWithABeard
SQLDBAWithABeard / findsqlpackagepath.ps1
Created March 12, 2019 20:50
compare dacpac and generate report in azure devops
#
# from https://raw.githubusercontent.com/Microsoft/vsts-tasks/master/Tasks/SqlAzureDacpacDeploymentV1/FindSqlPackagePath.ps1
#
function Get-SqlPackageOnTargetMachine
{
try
{
$sqlDacPath, $sqlVersion = Locate-HighestVersionSqlPackageWithSql
$sqlVersionNumber = [decimal] $sqlVersion
@SQLDBAWithABeard
SQLDBAWithABeard / chocolately.ps1
Last active April 13, 2022 14:39
Laptop install
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install chocolatey -y
choco install 1password -y
choco install azure-data-studio -y
choco install azure-functions-core-tools-3 -y
choco install azure-cli -y
choco install bicep -y
choco install chocolatey-core.extension -y
@SQLDBAWithABeard
SQLDBAWithABeard / Generate - Does SP exist tests
Last active May 1, 2019 09:34
Generating TSQLT - from SQLStad
# Import the dbatools module
Import-Module dbatools
# Set the global values
$instance = 'localhost,15789'
$db = 'WideWorldImporters'
$date = (Get-Date).ToString('yyyy-MM-dd')
$creatorName = 'Beardy McBeardFace'
$cred = Import-Clixml -Path D:\Creds\containersa.xml
$TestClass = 'TestExistence'
$instance = ''
$Databases = ''
$CompressedSize = @{Name='Compressed';Exp={[math]::round($_.CompressedBackupSize/1Tb,3)}}
$Size = @{Name = 'Size';Exp={[math]::Round($_.TotalSize/1Tb,3)}}
## Get the info
Get-DbaBackupHistory -SqlInstance $instance -Database $databases -Last -Raw | Select Database, Path, $CompressedSize , $Size
#get the total size of files
(Get-DbaBackupHistory -SqlInstance $instance -Database $databases -Last -Raw | Select Database, Path, $CompressedSize | Measure-Object Compressed -Sum).Sum
@SQLDBAWithABeard
SQLDBAWithABeard / prompt.ps1
Last active March 21, 2024 07:16
new improved colourful prompt
######## POSH-GIT
# with props to https://bradwilson.io/blog/prompt/powershell
#
#
# Now for this to work most beautifully - you will need to have the latest posh-git module
#
# You will also need the MesloLGM Nerd Font Mono font
# from here https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Meslo/M/Regular/complete/Meslo%20LG%20M%20Regular%20Nerd%20Font%20Complete.ttf
# if you are super nerdy
# or