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 / Search-AzureDevOpsCode.ps1
Last active October 14, 2023 01:29
PowerShell script to find code in Azure DevOps service
#requires -Version 7.2
<#
.SYNOPSIS
Azure DevOps REST API to get a results across an organization based on provided search text, just as you would in the web UI
.NOTES
https://learn.microsoft.com/en-us/rest/api/azure/devops/search/code-search-results/fetch-code-search-results?view=azure-devops-rest-7.1&tabs=HTTP#coderesult
Based on provided answer from SO: https://stackoverflow.com/a/64973447/12974596
.EXAMPLE
./Search-AzureDevOpsCode.ps1 -OrganizationName Company -Project Enterprise -SearchFilter "ext:yml AND somestringvalue" -AzAccessToken (Get-AzAccessToken)
@wsmelton
wsmelton / docker-compose
Created September 6, 2023 13:55
Initialize SQL Server containers via Docker compose
version: '3.7'
services:
sql17:
container_name: 'sql17'
platform: linux/amd64
image:
mcr.microsoft.com/mssql/server:2017-latest
environment:
@wsmelton
wsmelton / Get-AzComputeResourceDetails.ps1
Created September 20, 2022 14:25
Get the compute resource details for VM and Disk into an Excel file
#Requires -Modules ImportExcel, Az.Accounts, Az.Compute
<#
.SYNOPSIS
Retrieve region specific Sku details for Virtual Machines and Managed Disks into an Excel file
.EXAMPLE
./Get-AzComputeResourceData.ps1 -Regions 'westus2','westus3' -ExcelFileName 'c:\temp\azComputeResourceSku.xlsx
#>
[cmdletbinding()]
param(
@wsmelton
wsmelton / Find-AppRegistrationExpiringSecrets.ps1
Created August 31, 2022 16:53
Use Az.Resources commands to pull App Registrations' Client Secret expiration status from Azure AD - Requires PowerShell 7+
#requires -Module Az.Resources
#requires -Version 7
<#
.SYNOPSIS
Based on Get-AppRegistrationExpiration by Cj-Scott
https://github.com/Cj-Scott/Get-AppRegistrationExpiration
#>
$applications = Get-AzADApplication | Where-Object { $_.KeyCredentials.DisplayName -gt 0 }
$today = (Get-Date).ToUniversalTime()
@wsmelton
wsmelton / Get-AzRegionZone.ps1
Created April 19, 2022 20:54
Get a list of Zones available in a given Azure Region
param(
[string]$Location,
[string]$SubcriptionName
)
$subObj = Get-AzSubscription -SubscriptionName $SubscriptionName
Set-AzContext -SubscriptionObject $subObj
$payload = @{
location = $location
subscriptionIds = @("subscriptions/$($subObj.Id)")
[cmdletbinding()]
param(
[string]
$VMName
)
$scriptBlock = {
$clusterNetworkNames = Get-ClusterResource | Where-Object ResourceType -eq 'Network Name'
foreach ($n in $clusterNetworkNames) {
if ($n.Name -match 'SQL Network Name') {
$hostValue = $n.Name.TrimStart('SQL Network Name (').TrimEnd(')')
@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 / Find-MissingCommands.ps1
Last active December 31, 2021 19:54
Commands index page comparison to Commands in dbatools module (cmdlet and function)
function Find-MissingCommands {
<#
.SYNOPSIS
Find missing commands between the dbatools.io/commands and dbatools Module public functions
.PARAMETER ModulePath
Path to dbatools local repository
.PARAMETER CommandPagePath
Full path to the index.html commands page (e.g. c:\git\web\commands\index.html)
#$PSDefaultParameterValues = @{ "*:Credential" = (Get-Secret username) }
if ($psedition -ne 'Core') {
[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12", "Tls11", "Tls", "Ssl3")
}
function Prompt {
$major = $PSVersionTable.PSVersion.Major
$minor = $PSVersionTable.PSVersion.Minor
$patch = $PSVersionTable.PSVersion.Patch
if ($major -lt 6) {
Write-Host "[PS $($major).$($minor)] [" -NoNewline
@wsmelton
wsmelton / copy-dbalogin-parameters.md
Last active July 21, 2021 20:12
A look into the parameters of Copy-DbaLogin

SQL Server migrations, the bain in most DBA's lives when they find out one is coming up. At that top of the list, along with finding out, you need to test your database DR strategy that is fully documented 😉 😉.

Still, one of the most common tasks that can be in day-to-day activity is getting logins created between various SQL Server instances. Say you have to support multiple environments for a given application database, creating that login 3, 4, 5 different times manually using SSMS 😧! dbatools includes a ton of commands that help in migrations.

Do you have multiple Availability Groups (AG) deployed in your environment? AGs that have 3, 4, 6 replicas that you are adding a login to one require adding it to all the other replicas?

These scenarios, among many others, are where Copy-DbaLogin can help make your life easier and give you more time to catch up on other things.

Copy-DbaLogin