Skip to content

Instantly share code, notes, and snippets.

View jpomfret's full-sized avatar

Jess Pomfret jpomfret

View GitHub Profile
@jpomfret
jpomfret / kubernetes_clearUpEvictedPods.ps1
Last active February 18, 2026 20:16
Kubernetes: Clear up evicted pods
# quicker method
# get
kubectl delete pod --all-namespaces --field-selector=status.phase=Failed
# and delete
kubectl delete pod --all-namespaces --field-selector=status.phase=Failed
@jpomfret
jpomfret / sp_indexinfo.sql
Created February 4, 2025 11:24
sp_indexinfo
-- Index stats are from the last restart - this will show you the days
select datediff(d,create_date,getdate())
from sys.databases
where name = 'tempdb'
/*
You can either run this with specific schema or table names or you can run it with % in those variables to get all indexes for a schema or for the whole database
@schPat SYSNAME = '%'
,@tblPat SYSNAME = '%'
@jpomfret
jpomfret / backuphistory.sql
Created December 23, 2024 15:21
backupHistory
use msdb
select top 100 name,database_name,
case type
when 'D' then 'Full'
when 'I' then 'Differential'
when 'L' then 'Log' end as backupType, backup_start_date, backup_finish_date, DATEDIFF(MINUTE,backup_start_date,backup_finish_date) as durationMins,
cast ((compressed_backup_size/1000)/1000 as int) as compressed_backup_size_MB,
cast ((backup_size/1000)/1000 as int) as backup_size_mb,
user_name, first_lsn, last_lsn, checkpoint_lsn, database_backup_lsn, is_copy_only
@jpomfret
jpomfret / acr-storage.ps1
Last active March 1, 2025 08:14
Get ACR Storage sizes
$registry='DmmPortalAcr'
write-host "Getting all repos..."
$repos=(az acr repository list -n $registry -o tsv)
$progress=0
$total_items=$repos.Count
$res = @()
@jpomfret
jpomfret / AppRegExpiringSecrets.ps1
Last active September 6, 2024 14:43
Get Expiring App Registration Secrets
# collect data
$applications = Get-AzADApplication
$servicePrincipals = Get-AzADServicePrincipal
# match service principals with applications
$appWithCredentials = @()
$appWithCredentials += $applications | Sort-Object -Property DisplayName | ForEach-Object {
$application = $_
$sp = $servicePrincipals | Where-Object AppId -eq $application.AppId
@jpomfret
jpomfret / badges.txt
Last active July 24, 2024 12:48
empty
‎‎​
--restore history
SELECT rh.restore_date,bs.backup_start_date, rh.stop_at, rh.destination_database_name,
case rh.restore_type
when 'D' then 'Full'
when 'I' then 'Differential'
when 'L' then 'Log' end as Restore_Type, bs.server_name as SourceServer, bs.database_name as SourceDB, backup_size as backupsize_bytes, (backup_size * 0.000001) as backupsize_MB
FROM MSDB.DBO.restorehistory rh
inner join msdb.dbo.backupset bs
on rh.backup_set_id = bs.backup_set_id
ORDER BY rh.restore_date DESC
<#
.SYNOPSIS
Function to get a list of Quarterfinal scores from CrossFit Games API for a specific affiliate
.DESCRIPTION
Function to get a list of Quarterfinal scores from CrossFit Games API for a specific affiliate
.PARAMETER affiliateName
The name of the affiliate to filter by, e.g. 'CrossFit Southampton'
@jpomfret
jpomfret / PowerShellReport.ps1
Last active November 18, 2023 11:18
Create great looking email reports with PowerShell and PSHTML
## Using PSHTML to create great looking email reports
## Blog post with more information: https://jesspomfret.com/pshtml-email-reports
## Email details
$emailTo = '[email protected]'
$emailFrom = '[email protected]'
$emailSubject = ('Authors: {0}' -f (get-date -f yyyy-MM-dd))
$smtpServer = 'smtp.server.address'
## Query details
@jpomfret
jpomfret / SQLPermissionsFromSpreadsheet.ps1
Created December 22, 2022 12:00
Takes permissions from a spreadsheet and assigns them to the SQL Servers. If the logins are SQL Logins it will prompt for the password to be entered.
$perms = import-excel -Path C:\Temp\spreadsheetName.xlsx -WorksheetName permissions
<#
The spreadsheet should have a worksheet named permissions with the following columns:
Username Server Database Permissions
JessUser mssql1 database1 db_datareader
UserName2 mssql2 database2 db_datareader, db_datawriter, execute
#>