Skip to content

Instantly share code, notes, and snippets.

View nanoDBA's full-sized avatar

nanoDBA nanoDBA

View GitHub Profile
@nanoDBA
nanoDBA / Proposed SQL Server Patching Approach.txt
Last active February 26, 2023 19:37
An approach I've been using for the last 4 years or so to deploy SQL Server Cumulative Updates
Proposed SQL Server Patching Approach
We do not patch to the absolute latest cumulative update(CU).
Rather, we strive to patch to the cumulative update(CU) that
was released without any intermediate releases(such as hotfixes)
between it and the most recent CU. Basically N-1 as long as
there aren't any hotfixes. If there were hotfixes then we'll wait
until two CU subsequent releases have occurred
without hotfixes in between the two to deploy the CU.
@nanoDBA
nanoDBA / Remove-SoundAndStillness.ps1
Last active August 13, 2024 07:40
FFmpeg Remove video frames without motion and remove audio track
$filename = "A:\Users\kilroy\Remove_lack_of_motion.mp4"
# Use ffprobe to extract the avg_frame_rate
$fpsFraction = ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 "$filename"
$fps = Invoke-Expression "($fpsFraction)"
# Convert fractional fps to a numeric value if necessary
if ($fpsFraction -match "/") {
$fpsParts = $fpsFraction -split "/"
$fps = [double]$fpsParts[0] / [double]$fpsParts[1]
<#
.SYNOPSIS
BoxStarter script to configure Windows 10 development PC.
.DESCRIPTION
You might need to set:
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass
@nanoDBA
nanoDBA / Get-Process-SSMSUsers.ps1
Created February 6, 2023 22:50
Shows users currently using process Ssms.exe in a loop executing every 55 minutes
do {
$ssms = Get-WmiObject -Class Win32_Process -Filter "name = 'Ssms.exe'"
<# Timer/time bomb stub #> $now = Get-Date
$timespan = New-TimeSpan -Start $now -End (Get-Date).AddMinutes(55) # '20:25') #'2077-10-09 19:30'
Write-Host -ForegroundColor magenta "SSMS active user count: $(($ssms.GetOwner()).User.count)"
Write-Host -ForegroundColor magenta "SSMS active users: $(($ssms.GetOwner()).User)"
Write-Host -ForegroundColor magenta "Sleeping until $((Get-date).AddSeconds($timespan.TotalSeconds)) ..."
Start-Sleep -Seconds $timespan.TotalSeconds
}
while ( ($ssms.GetOwner()).User.count -GT 0 )
@nanoDBA
nanoDBA / Get-Command_Line_History_for_all_users.ps1
Last active January 25, 2023 13:49
Loop through PSReadline histories for all user profiles and copy them to the clipboard
### Get Command Line History for all users
# source: https://gist.github.com/nanoDBA/48f2cd1eab1e4433a97bd106e0dac08d
$dirs = (Get-ChildItem -Directory (Split-Path $env:USERPROFILE)).FullName | Sort-Object
$allHistories = foreach($profileDir in $dirs){
Write-Output "### $profileDir"
$historySavePath = "$profileDir\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"
if(!(Test-Path ($historySavePath) )) {
Write-Output "### $historySavePath does not exist"
}
@nanoDBA
nanoDBA / Get-Daylight.ps1
Last active January 2, 2025 17:53
How many minutes of daylight are there in a given day?
# 🌞 Looking forward to more daylight! 🌞
# https://stackoverflow.com/questions/63236774/powershell-return-only-sunrise-sunset-time/63237047#63237047
# using API from https://sunrise-sunset.org/api
# Location Coordinates (enter your location)
$lat = 35.787743 # Latitude
$long = -78.644257 # Longitude
# Fetching Data
Write-Host "☀️ Fetching daylight data... Every day gets a little brighter! ☀️`n"
# DANGER # Server Core? ---OPTIONAL--- Setting PowerShell as the Default Shell Manually
#If you've only got one server, a couple of servers or maybe your Server Core machines are workgroup members so you can't use Group Policy and if any of these are true, the manual method is for you. It's a simple PowerShell one-liner:
# source: https://richardjgreen.net/setting-powershell-default-shell-server-core/
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name Shell -Value 'PowerShell.exe -NoExit'
<#what else has been run as this user? #>Get-Content (Get-PSReadlineOption).HistorySavePath | Set-Clipboard
--AG-Resume.sql for SQL Agent job
--Check Sync State and Execute Resume
DROP TABLE IF EXISTS #agAynamicSqlResume
DECLARE @sqlCommand NVARCHAR(max)
SELECT ';ALTER DATABASE [' + Db_name(DRS.database_id) + '] SET HADR RESUME' AS [resume_sql],
AGS.name AS AGGroupName,
AGL.dns_name AS Listener_dns_name,
@nanoDBA
nanoDBA / Invoke-Robocopy.ps1
Created September 28, 2022 13:57
robocopy root of a volume unbuffered and multithreaded with 128 threads
#robocopy root of a volume multithreaded unbuffered
$description = 'SRV_Migration'
$source = '\\10.0.0.0\P$'
$target = 'P:'
$robocopyLogFilename = "$($target)\" + ( [string](Get-Date -format "yyyy-MM-dd_HH-mm-ss") ) + "_" + $($description) + "_(" + ($target).Substring(0,1) + ")_robocopy.log"
# exclude the Recycle Bin and sysvol folders, and exclude pagefile
robocopy $source $target * /E /W:10 /XD "System Volume Information" "`$RECYCLE.BIN" /LOG+:$robocopyLogFilename /NP /TEE /SEC /MT:128 /XF pagefile.sys /J
<#