Skip to content

Instantly share code, notes, and snippets.

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 / Get-AzComputeResourceDetails.ps1
Created September 20, 2022 14:25
Get the compute resource details for VM and Disk into an Excel file
View Get-AzComputeResourceDetails.ps1
#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+
View Find-AppRegistrationExpiringSecrets.ps1
#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
View Get-AzRegionZone.ps1
param(
[string]$Location,
[string]$SubcriptionName
)
$subObj = Get-AzSubscription -SubscriptionName $SubscriptionName
Set-AzContext -SubscriptionObject $subObj
$payload = @{
location = $location
subscriptionIds = @("subscriptions/$($subObj.Id)")
View Get-ClusterNetworkFQDN.ps1
[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
View SystemHealth_Parsed_DeadlockInfo.sql
;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)
View Find-MissingCommands.ps1
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)
View current_profile.ps1
#$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
View copy-dbalogin-parameters.md

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

@wsmelton
wsmelton / sqlcommunity-channel.md
Last active April 28, 2021 15:17
Table listing of channels in SQL Community Slack
View sqlcommunity-channel.md
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....
@wsmelton
wsmelton / SSMS_ProductInformation.ps1
Last active January 14, 2021 21:42
Listing of ProductID and Product Name for SSMS install with PowerShell DSC
View SSMS_ProductInformation.ps1
<#
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