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
CREATE TABLE myTable (col1 varchar(2))
INSERT INTO myTable ('ts');
GO
$os = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' -ErrorVariable $osinfoError
$osInfoData = [pscustomobject]@{
"ProductName" = $os.ProductName;
"Version Number" = $os.CurrentVersion
};
#region Links
<#
NOTE: Links are subject to change by Microsoft
Server Configuration Options BOL:
SQL Server 2014 - http://technet.microsoft.com/en-us/library/ms189631(v=sql.120).aspx
SQL Server 2012 - http://technet.microsoft.com/en-us/library/ms189631(v=sql.110).aspx
SQL Server 2008 R2 - http://technet.microsoft.com/en-us/library/ms189631(v=sql.105).aspx
SQL Server 2008 - http://technet.microsoft.com/en-us/library/ms189631(v=sql.100).aspx
SQL Server 2005 - http://technet.microsoft.com/en-us/library/ms189631(v=sql.90).aspx
SQL Server 2000 - http://technet.microsoft.com/en-us/library/aa196706(v=sql.80).aspx
@wsmelton
wsmelton / SystemHealth_Parsed_DeadlockInfo.sql
Created October 6, 2016 20:00
Script to parse Deadlock information from System_Health XEvent session in SQL Server
;WITH xDeadlock (Contents)
AS
(
select CAST(XEventData.XEvent.value('(data/value)[1]', 'varchar(max)') as xml) as DeadlockGraph
FROM
(select CAST(target_data as xml) as TargetData
from sys.dm_xe_session_targets st
join sys.dm_xe_sessions s on s.address = st.event_session_address
where name = 'system_health') AS Data
CROSS APPLY TargetData.nodes ('RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData (XEvent)
@wsmelton
wsmelton / Code_dbatools_settings.json
Created May 22, 2017 13:55
Color settings for VS Code and dbatools theme
//playing with color settings
"workbench.colorCustomizations": {
"activityBar.background": "#F0EBD7",
"activityBar.foreground": "#C9A735",
"activityBarBadge.foreground": "#3F3C3D",
"activityBarBadge.background": "#FFFFFF",
"panel.background": "#F3F7F2",
"statusBar.background": "#BFB297",
"statusBar.foreground": "#FFFFFF",
"sideBar.background": "#383636",
@wsmelton
wsmelton / Out-CodeView.ps1
Created July 1, 2017 02:51
Generate Content View utilizing VS Code from an input object
<#
.SYNOPISIS
Generate an HTML view that will open in an editor for VS Code
.NOTES
Add this to your Microsoft.VSCode_profile.ps1 file
.EXAMPLE
$results = Get-DbaSpConfigure -SqlInstance manatarms
Out-CodeView $results
#>
function Out-CodeView {
@wsmelton
wsmelton / Get-MyEc2Instance
Created September 17, 2017 22:05
Pull the list of EC2 instances running under your AWS account, based on using a tag called "owner"
param(
[string]$OwnerValue = 'melton',
[switch]$Raw
)
$myEc2Instances = Get-EC2Tag -Filter @{ Name="key"; Values="owner" },@{ Name="value";Values=$OwnerValue}, @{ Name="resource-type";Values="instance"}
$data = Get-EC2Instance -InstanceId $myEc2Instances.ResourceId | Select-Object -ExpandProperty Instances
if ($Raw) {
foreach ($d in $data) {
$value = ($d.Tags | Where-Object Key -eq Name).Value
@wsmelton
wsmelton / sql.json
Created April 26, 2018 22:48
SQL Ops Studio - User Snippets
{
"New SQL Login": {
"prefix": "new-sql-login",
"body": [
"CREATE LOGIN [${1:name of the login}] WITH PASSWORD = N'${2:password value}', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF;",
],
"description": "Create a new SQL Login"
},
"New Windows Login": {
"prefix": "new-windows-login",
@wsmelton
wsmelton / backup-history.sql
Created May 10, 2018 13:37
Get backup history details
SET NOCOUNT ON;
SELECT distinct t1.name AS 'DatabaseName'
,(datediff( ss, t3.backup_start_date, t3.backup_finish_date)) AS 'DurationInSeconds'
,t3.user_name AS 'UserResponsible'
,t3.name AS backup_name
,t3.description
,t3.backup_start_date
,t3.backup_finish_date
,CASE
@wsmelton
wsmelton / keybinds.json
Created July 30, 2018 14:10
My key bindings for VS Code
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "alt+up",
"command": "workbench.action.navigateUp"
},
{
"key": "alt+down",
"command": "workbench.action.navigateDown"
},