Skip to content

Instantly share code, notes, and snippets.

View chrisbrownie's full-sized avatar
🛩️
computering

Chris Brown chrisbrownie

🛩️
computering
View GitHub Profile
@chrisbrownie
chrisbrownie / cleanup.ps1
Created June 15, 2024 00:06
Clean up images in a folder, moving them to subfolders named YYYY-MM based on the image's creation date.
$screenshotsDir = "$($env:userprofile)\OneDrive\Pictures\Screenshots"
$fileType = "png"
$images = Get-ChildItem -Path $screenshotsDir -filter "*.$fileType"
for ($i=0; $i -lt $images.Length; $i++) {
$monthYearString = $images[$i].CreationTime.Year.ToString() + "-" + $images[$i].CreationTime.Month.ToString().PadLeft(2,"0")
$folder = Join-Path $screenshotsDir $monthYearString
if (-not (Test-Path -Path $folder -PathType Container)) {
@chrisbrownie
chrisbrownie / electric-blanket-prompt.yaml
Created April 27, 2023 07:50
Prompt to turn the electric blanket on on a cool evening
alias: Bedroom - Electric Blanket Question 2130
description: "Prompts to turn the electric blanket on if the temperature is below 13 deg C at 2130 and I'm home."
trigger:
- platform: time
at: "21:30:00"
condition:
- condition: zone
entity_id: person.me
zone: zone.home
- condition: template
# -------------------------------------------------------------------------------
# Script: Get-MessageSizeLimits.ps1
# Author: Chris Brown
# Date: 28/04/2011
# -------------------------------------------------------------------------------
# Import the Exchange Snap-ins
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue) -eq $null) {
Write-Verbose "Exchange 2010 snapin is not loaded. Loading it now."
try { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; Write-Verbose "Loaded Exchange 2010 snapin" }
catch { Write-Error "Could not load Exchange 2010 snapins!"; }
PS /Users/chris> Write-Log "Hello!"
[2018-09-14T08:27:35] Hello!
PS /Users/chris> Get-Content ./somelogfilename.log
[2018-09-14T08:27:35] Hello!
PS /Users/chris>
@chrisbrownie
chrisbrownie / SsmResetAdminPassword.py
Created April 11, 2018 01:13
Uses SSM to reset the administrator password of a Windows machine
#!/usr/local/bin/python
import argparse
import boto3
def resetPassword(instanceId, password, region, profile):
session = boto3.Session(profile_name=profile, region_name=region)
client = session.client('ssm')
runPwshDocument = 'AWS-RunPowerShellScript'
@chrisbrownie
chrisbrownie / Get-HappyHourDeals.ps1
Created March 7, 2018 05:38
Gets the current Virgin Australia happy hour deals. It's not great but it bloody works and that's all that matters
$HHUrl = "http://happyhour.virginaustralia.com/sale-on"
$page = Invoke-WebRequest -Uri $HHUrl
$flightDivs = $page.ParsedHtml.body.getElementsByClassName('card-flight')
foreach ($flightDiv in $flightDivs) {
New-Object -TypeName PSObject -Property @{
"From" = $flightDiv.getElementsByTagName("h3")[0].innerText.Split("`n")[0].Trim() -replace '\ to', ''
@chrisbrownie
chrisbrownie / DownloadOlympusPhotos.ps1
Last active February 4, 2018 09:46
Downloads photos from an Olympus camera
$CameraIp = "192.168.0.10"
$DateFrom = Get-Date "29 December 2017"
function Invoke-OLApiCommand {
Param(
[String]$Command,
[String]$Arguments
)
$CommandVerb = $Command.Split("_")[0]
@chrisbrownie
chrisbrownie / CopyFilesToOffice365Group.ps1
Last active February 19, 2018 23:36
Copies files from the local computer to an Office 365 Group
param(
[String]
$Path, #the path to the files to be uploaded
[String]
$siteUrl, #this is the URL of the Group in the format https://contoso.sharepoint.com/sites/yourGroupName
[String]
$listName = "Shared Documents"
#this is the path within the site to the place where you want to put the files
@chrisbrownie
chrisbrownie / Invoke-Gist.ps1
Last active February 26, 2018 23:05
Invoke-Gist is a PowerShell function that allows you to invoke a gist by ID or URL.
function Invoke-Gist {
Param(
[String]
$Identity,
[String]
$Arguments
)
$gistBase = "https://api.github.com/gists/"
@chrisbrownie
chrisbrownie / HelloAgain.ps1
Last active January 18, 2018 22:34
Demo script that generates an output
New-Object -TypeName PSObject -Property @{Message="Hello, again!"}