Skip to content

Instantly share code, notes, and snippets.

View jpomfret's full-sized avatar

Jess Pomfret jpomfret

View GitHub Profile
@jpomfret
jpomfret / ParseGarminWeightCSV.ps1
Last active July 29, 2022 08:57
Reformat the weight.csv you get when you download garmin connect weight data
# Login to https://connect.garmin.com/ & Navigate to 'Health Stats > Weight > 1 Year'
# at the top there is an export, that'll get you the csv.
# but the csv is in a poor format, with the date on the row above the data - this will reformat it for you
$weight = import-csv 'C:\Users\JessPomfret\Downloads\Weight.csv'
$counter = 0
$final = $weight.foreach{
if ( ($counter % 2) -eq 0) {
@jpomfret
jpomfret / AzureVMSnappyShots.ps1
Created October 21, 2022 12:27
AzureVMSnappyShots
# some variab;es
$resourceGroupName = 'rgTest'
$location = 'uksouth'
$vmName = 'rg-sm'
$snapshotName = ('snappyshot-SomethingUseful')
## take a snapshot of the disk
$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
$currentOsDisk = $vm.StorageProfile.OsDisk.Name
$snapshot = New-AzSnapshotConfig -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id -Location $location -CreateOption copy
@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
#>
@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 = 'me@jesspomfret.com'
$emailFrom = 'reports@jesspomfret.com'
$emailSubject = ('Authors: {0}' -f (get-date -f yyyy-MM-dd))
$smtpServer = 'smtp.server.address'
## Query details
<#
.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'
--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
@jpomfret
jpomfret / badges.txt
Last active July 24, 2024 12:48
empty
‎‎​
@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 / 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 / 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