Skip to content

Instantly share code, notes, and snippets.

View nanoDBA's full-sized avatar

nanoDBA nanoDBA

View GitHub Profile
@nanoDBA
nanoDBA / Get-DiskSpaceWithFreeGoal.ps1
Last active April 19, 2025 13:20
Checks disk space, shows extra space needed to meet target free %
<#
.SYNOPSIS
Retrieves disk space info from remote computers and computes the
extra free space needed to meet target free space percentages.
.DESCRIPTION
This function serves as a wrapper around the dbatools.io Get-DbaDiskSpace cmdlet,
extending its functionality with additional calculations.
It queries remote systems for disk space details, filters the output by specified
@nanoDBA
nanoDBA / Edit-EBSVolumes.ps1
Created April 12, 2025 14:07
Modifies AWS EBS volumes with enhanced validation and confirmation 🚀
function Edit-EBSVolumes {
<#
.SYNOPSIS
Modifies AWS EBS volumes with enhanced validation and confirmation 🔧🚀
.DESCRIPTION
This function lets you change multiple AWS EBS volumes in one go!
It supports modifications to volume type, size, IOPS, and throughput
with safety confirmations and detailed feedback.
@nanoDBA
nanoDBA / monitor_active_sessions.sql
Created March 12, 2025 15:06
Dump sp_WhoIsActive to a table
-- ████████ FILE: monitor_active_sessions.sql ████████
-- 🎯 MISSION OBJECTIVE: Real-time monitoring of active SQL Server sessions.
-- - If the table **does not exist**, create it.
-- - If the table **exists**, append new data.
-- - If you need a **hard reset**, uncomment the DROP TABLE line.
--
-- 🔧 USAGE:
-- 🎮 Execute in SSMS or a SQL Agent job for continuous ops.
-- 🔬 Uncomment DROP TABLE if you want to refresh the dataset.
@nanoDBA
nanoDBA / Get-EC2VolumeModificationDetails.ps1
Created February 13, 2025 22:22
Retrieves AWS EC2 volume modification records (size, IOPS, volume type changes, etc) and appends the associated instance name. Uses AWS Tools for PowerShell
<#
.SYNOPSIS
Retrieves AWS EC2 volume modification records and useful metadata.
🚀 Because sometimes we need speedy volume modifications!
.DESCRIPTION
The Get-EC2VolumeModificationDetails function retrieves modification details
for a list of specified EC2 volumes such as size, IOPS, volume type changes,
etc. It uses AWS SDK for .NET to interact with AWS EC2 services.
🤖 This function fetches the modification details and the associated instance
@nanoDBA
nanoDBA / Get-RecommendedSqlCU.ps1
Last active November 21, 2024 13:57
Finds the recommended N-1 cumulative update for SQL Server based on patching strategy that avoids intermediate releases
<#
.SYNOPSIS
Finds the recommended N-1 cumulative update for SQL Server based on patching strategy that avoids intermediate releases
.DESCRIPTION
This script queries a Google Sheets document containing SQL Server cumulative update information
and determines the recommended N-1 cumulative update based on a patching strategy that avoids
intermediate releases (e.g., hotfixes, security updates) between cumulative updates.
The script outputs the recommended cumulative update, its release date, and a link to more details.
The patching strategy is defined as follows:
@nanoDBA
nanoDBA / ServiceBrokerLogNoiseReductionEndpoint.sql
Created November 12, 2024 23:23
Creates SQL Server Service Broker endpoint on port 4022 to reduce noise in the SQL Server error log (ERRORLOG). Includes port availability checks, conditional creation, logging, and optional code to stop and drop endpoint if needed.
/* Add script to create Service Broker endpoint for log noise reduction
source idea: https://slavasql.blogspot.com/2019/11/errorlog-flooded-with-service-broker.html
- Creates ServiceBroker_LogNoiseReduction endpoint on port 4022
- Includes checks for port availability and existing endpoint
- Adds conditional logging for successful creation, start, and errors
- Optional code to stop and drop endpoint if needed
50001: Used for notifying if port 4022 is already in use.
50002: Indicates the endpoint was created and started successfully.
@nanoDBA
nanoDBA / Get-ExplicitLogonEvents.ps1
Created October 4, 2024 20:03
Gets 4648 Explicit Logon Events from Windows Event Log Author: Lee Christensen (@tifkin_)
function Get-ExplicitLogonEvents {
<#
.SYNOPSIS
Gets 4648 Explicit Logon Events from Windows Event Log
Author: Lee Christensen (@tifkin_)
# https://github.com/threatexpress/red-team-scripts/blob/3121db5d53a25d66afa01afb3bf0487d919d1846/HostEnum.ps1#L1552
#>
@nanoDBA
nanoDBA / Reboot.ps1
Created October 4, 2024 19:24
Reboots machine with a warning message to logged on users after specified number of minutes - defaults to 15 minute delay Reboot.ps1 -DelayMinutes 20
#requires -version 5.0
#Requires -RunAsAdministrator
<# DANGER REBOOTING!
This is meant for a local machine in a scheduled task
and is not handling remoting or remote credentials
#>
[CmdletBinding()]
param (
[Parameter()][int]$DelayMinutes = 15 #default to 15 minute delay if this parameter is not supplied
)
@nanoDBA
nanoDBA / Start-Sleep Magenta.ps1
Created September 6, 2024 20:16
Sleep 5 hours in console/script
# Store TimeSpan object in variable $timespan
$timespan = New-TimeSpan -Start (Get-Date) -End (Get-Date).AddHours(5) #(Get-Date).AddDays(1).Date.AddHours(5) #careful with this - syntax is weird
# Print a message to the console in magenta color indicating the time the script will resume execution
Write-Host -ForegroundColor magenta "Sleeping until $((Get-date).AddSeconds($timespan.TotalSeconds)) ..."
# Pause the execution of the script for a number of seconds equal to the total seconds of the $timespan
Start-Sleep -Seconds $timespan.TotalSeconds
@nanoDBA
nanoDBA / database_role_securables_query.sql
Created August 22, 2024 10:37
Retrieve securables and permissions for any specified database role. Uses a variable for the role name and prompts the user if the role name is not provided. Modeled after SSMS Securables page of Database Roles properties
-- database_role_securables_query.sql
-- modeled after SSMS Securables page of Database Roles properties
DECLARE @RoleName NVARCHAR(128);
SET @RoleName = ''; -- Replace with role name or leave empty for testing
IF @RoleName = ''
BEGIN
SELECT 'Please provide a valid role name to query securables' AS Message;