Skip to content

Instantly share code, notes, and snippets.

View wsmelton's full-sized avatar
🦆
Little bit of this, little bit of that

Shawn Melton wsmelton

🦆
Little bit of this, little bit of that
View GitHub Profile
@wsmelton
wsmelton / PBM-Test-Policy-Condition.sql
Created September 6, 2018 01:36
Sample policy and conditions
/* All Conditions */
DECLARE @condition_id INT
EXEC msdb.dbo.sp_syspolicy_add_condition
@name=N'AutoShrink',
@description=N'Verify AutoShrink is disabled',
@facet=N'Database',
@expression=N'<Operator>
<TypeClass>Bool</TypeClass>
<OpType>EQ</OpType>
<Count>2</Count>
@wsmelton
wsmelton / SSMS_ProductInformation.ps1
Last active January 14, 2021 21:42
Listing of ProductID and Product Name for SSMS install with PowerShell DSC
<#
Listing of the required information to install SQL Server Management Studio via the Package resource with PowerShell DSC.
# Example config:
Configuration InstallSSMS {
Package InstallSsms {
Ensure = "Present"
ProductID = <GUID value>
Name = Full SSMS Name that displays in Program Features
Path = SSMS-Setup-ENU.exe
@wsmelton
wsmelton / dbatools.code-snippets
Last active October 13, 2018 16:41
VS Code snippets for dbatools functions
{
// Snippets to be used for creating new functions with dbatools module.
// These snippets follow our general standard on the base parameters and properties we require in a function.
// This requires VS Code 1.28 (September build) or higher, that supports snippets scoped to the workspace/project level
// https://code.visualstudio.com/updates/v1_28#_project-level-snippets
// To create the file: CTRL + SHIFT, P then type in Preferences: Configure User Snippets
// Select the option for the project "dbatools"
// Paste the contents of this gist and save the file.
@wsmelton
wsmelton / download.ps1
Created January 4, 2019 02:23
Two options for downloading somethingsomething.exe from the Internet
Start-BitsTransfer -Source "https://yourbusiness.you/somethingsomething.exe" -Output "C:\MyBusiness\SomethingSomething.exe" -Asynchronous
(New-Object System.Net.WebClient).DownloadFile("https://yourbusiness.you/somethingsomething.exe","C:\MyBusiness\SomethingSomething.exe")
@wsmelton
wsmelton / AzConnection_Runbook.ps1
Created January 10, 2019 15:26
Basic template for any runbook in Azure Automation to connect to subscription and access other resources
#region Az Connection
$RunAsCn = Get-AutomationConnection -Name "AzureRunAsConnection"
$cnParams = @{
"ServicePrincipal" =$true;
"TenantID" =$RunAsCn.TenantID;
"ApplicationId" =$RunAsCn.ApplicationID;
"CertificateThumbprint" =$RunAsCn.CertificateThumbprint;
}
$null = Connect-AzureRmAccount @cnParams
$null = Set-AzureRmContext -SubscriptionId $RunAsCn.SubscriptionID > $null
@wsmelton
wsmelton / DownloadDbatools.ps1
Created January 15, 2019 19:29
Download from PowerShell Gallery via API
$package = 'https://powershellgallery.com/api/v2/package/dbatools'
$zipPath = 'C:\temp\dbatools.zip'
(New-Object System.Net.WebClient).DownloadFile($package, $zipPath)
$extractPath = 'C:\temp\modules\'
[io.compression.zipfile]::ExtractToDirectory($zipPath, $extractPath)
# verify
ipmo "$extractPath\dbatools.psd1"
Get-Module dbatools
@wsmelton
wsmelton / DownloadDbatools-GitHub.ps1
Created January 15, 2019 19:51
Download dbatools from GitHub - uses shortlink for dbatools.io
$zipFile = 'C:\temp\dbatools.zip'
$url = 'https://dbatools.io/zip'
$extractPath = 'C:\temp\modules\'
(New-Object System.Net.WebClient).DownloadFile($url, $zipfile)
[io.compression.zipfile]::ExtractToDirectory($zipPath, $extractPath)
# You can stop right there and will just use following to import
Import-Module C:\temp\modules\dbatools-master\dbatools.psd1
# Other option is to rename the folder
@wsmelton
wsmelton / details.md
Last active February 8, 2019 21:38
General script used in projects that allows you to validate an environment.

Purpose

On average I'm working with Docker for Windows on my machine when I need to analyze some data or say build reports from collected metric data of a given client. The environment.ps1 script provided simply does some validates for me and ensures everything is in order.

No Pester

I'm not using Pester for the testing of the environment because on average I don't have machines in client environments with that installed. Just making it more universal for right now but if you want to take it and go with using Pester...by all means.

Check for Docker

@wsmelton
wsmelton / prompt.ps1
Last active September 9, 2020 23:54
My prompt that is part of my profile for PowerShell
function Prompt {
$major = $PSVersionTable.PSVersion.Major
$minor = $PSVersionTable.PSVersion.Minor
$patch = $PSVersionTable.PSVersion.Patch
if ($major -lt 6) {
Write-Host "[PS $($major).$($minor)] [" -NoNewline
} else {
$patch = $PSVersionTable.PSVersion.Patch
Write-Host "[PS $($major).$($minor).$($patch)] [" -NoNewline
}
@wsmelton
wsmelton / sqlcommunity-channel.md
Last active April 28, 2021 15:17
Table listing of channels in SQL Community Slack
MemberCount Name Purpose
9363 announcements welcome to SQL Community Slack! You can click on the "Channels" to browse all the public channels. This channel is for announcements by moderators.
9129 sqlhelp Another way to ask for help besides Twitter....