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 / 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 / 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 / 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 / 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 / restore database
Created June 21, 2018 11:54
Restore-DbaDatabase, timings and error handling
$file = ## whatever Get-ChildItem or path
$Instance
$JobName = 'Restore' + (Get-Random).ToString()
$Date = (Get-Date).DateTime.ToString()
$msg = "$Date - Starting Job $JobName to restore the database"
## LoggingFunction $msg
$pscmdlet.WriteVerbose($msg)
Describe " This is a test"{
Context "Scoping my tests" {
$Drives = (Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name.Length -eq 1}).Name
$TestCases = @()
$Drives.ForEach{
$Testcases += @{'DriveLetter' = "$($_):"}
}
It "Checking if bitlocker is fully encrypted on Drive <DriveLetter>" -TestCases $Testcases {
Param($DriveLetter)
@SQLDBAWithABeard
SQLDBAWithABeard / gist:1fb7419b010a48b322735dd806c3c3e4
Created November 28, 2017 13:46
All hail Lee Holmes - This is his Test-PSRemoting function
function Test-PsRemoting
{
# Written by Lee Holmes - http://www.leeholmes.com/blog/2009/11/20/testing-for-powershell-remoting-test-psremoting/
param(
[Parameter(Mandatory = $true)]
$computername
)
try
{
@SQLDBAWithABeard
SQLDBAWithABeard / 00 - Plaster.ps1
Last active April 16, 2018 15:04
Code for VSTS Build and release for PowerShell Gallery
$ModuleName = 'BeardAnalysis'
$Description = "This is a demo module for demoing Plaster and TDD with Pester and CI with VSTS to the PowerShell Gallery"
$plaster = @{
TemplatePath = "GIT:\PlasterTemplate" #(Split-Path $manifestProperties.Path)
DestinationPath = "Git:\$ModuleName"
FullName = "Rob Sewell"
ModuleName = $ModuleName
ModuleDesc = $Description
Version = '0.9.18'
## Load assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.SqlParser") | Out-Null
$ParseOptions = New-Object Microsoft.SqlServer.Management.SqlParser.Parser.ParseOptions
$ParseOptions.BatchSeparator = 'GO'
## No Errors
$Sql = "Select * from sys.sysdatabases"
$Script = [Microsoft.SqlServer.Management.SqlParser.Parser.Parser]::Parse($SQL, $ParseOptions)
$Script.Errors
function Get-SQLDiagRecommendations {
[cmdletbinding()]
Param()
if(!(Get-ChildItem Env:MS_SQLDiag_APIKey -ErrorAction SilentlyContinue)){
Write-Warning "You have not created an Environment Variable MS_SQLDiag_APIKey to hold the APIKey
You can do this using [Environment]::SetEnvironmentVariable(`"MS_SQLDiag_APIKey`", `"APIKEYGOESHERE`", `"User`")
You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ "
}
}