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
# There must be a better way to do this
$Sps = $srv.Databases['DBA-Admin'].StoredProcedures.Where{$_.Schema -eq 'dbo'}.Name
$Return.OlaProcs = $true
$I = 4
if($Sps -notcontains 'CommandExecute')
{$I --}
if($Sps -notcontains 'DatabaseBackup')
{$I --}
if($Sps -notcontains 'DatabaseIntegrityCheck')
{$I --}
@SQLDBAWithABeard
SQLDBAWithABeard / find-DBAAgentJob.Tests.ps1
Created November 8, 2016 20:43
Pester test for find-dbaagentjob mocking connect-sqlserver
#Generic tests at the top - interesting stuff at line 108
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.', '.')
. "$here\$sut"
"$here\$sut"
. "$Here\SharedFunctions.ps1"
Import-Module PSScriptAnalyzer
$Rules = Get-ScriptAnalyzerRule
$Name = $sut.Split('.')[0]
@SQLDBAWithABeard
SQLDBAWithABeard / gist:680db5d8d5635f1da414fb78a2971a9e
Created November 22, 2016 07:06
dbareports agent info table and code
USE [DBADatabase]
GO
/****** Object: Table [Info].[Alerts] Script Date: 21/11/2016 16:50:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
$Webpage = iwr http://tugait.pt/2017/speakers/
$SpeakersImages = $webpage.Images.Where{$_.class -eq 'speaker-image lazyOwl wp-post-image'}.src
$Faces = @()
foreach($URL in $SpeakersImages)
{
$jsonBody = @{url = $URL} | ConvertTo-Json
$apiUrl = "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur"
$apiKey = 'c9c98da91bbb4b1490bd24e136353766'
$headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey }
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/ "
}
}
## 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
@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'
@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
{
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 / 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)