Skip to content

Instantly share code, notes, and snippets.

View JPRuskin's full-sized avatar

James Ruskin JPRuskin

View GitHub Profile
@JPRuskin
JPRuskin / AOC2021.md
Last active December 7, 2021 17:42
Solutions to Advent of Code 2021, probably in PowerShell.

Advent of Code 2021

CodeTree thanks to obalunenko

This gist contains some Advent of Code solutions for the 2021 season.

function Get-DeploymentTiming {
param(
[Parameter(Mandatory)]
[string]$ResourceGroupName,
[string]$DeploymentName
)
begin {
$Context = Get-AzContext
if (-not $script:Token -or $Token.ExpiresOn.LocalDateTime -lt [DateTime]::Now) {
$script:Token = Get-AzAccessToken
@JPRuskin
JPRuskin / ConnectToAzVm.ps1
Created July 13, 2021 17:57
Wrangles a VM such that you can connect to it, assuming no Public IP and an NSG blocking 3389.
# WRANGLE ResourceGroup
[CmdletBinding()]
param(
$ResourceGroupName = 'ade-test'
)
<# Readd Public IP #>
$mgtNic = Get-AzNetworkInterface -ResourceGroupName $ResourceGroupName -Name *-nic
if (-not $mgtNic.IpConfigurations[0].PublicIpAddress.Id) {
if (-not ($mgtPublicIp = Get-AzPublicIpAddress -ResourceGroupName $ResourceGroupName -Name 'tempip')) {
@JPRuskin
JPRuskin / Get-AzLabCredential.ps1
Created July 13, 2021 10:06
A function that returns a credential object, given a pair of secrets in a KeyVault
#requires -Modules Az.Accounts, Az.KeyVault
using namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
using namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
# function Get-AzLabCredential {
<#
.Synopsis
A function that returns a credential object, given a pair of secrets in a KeyVault
.Example
using namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
function Invoke-AzVmScript {
<#
.Synopsis
Runs a script block or file on a given Azure VM
.Notes
This takes a surprisingly long time to run, and is a bit flaky. Any output past 4096 characters is not returned.
#requires -Modules Az.Accounts
using namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
#function Add-JitAccess {
<#
.Synopsis
Adds a JIT exception to VMs in the provided Resource Group
.Notes
Until we have an Az.Accounts version that works with Az.Security, we cannot use the provided cmdlets to maintain JIT. This is a workaround.
.Example
@JPRuskin
JPRuskin / AOC2020.md
Last active December 10, 2020 09:24
Advent of Code 2020

Advent of Code

This gist contains my attempt(s) to solve the Advent of Code 2020 puzzles, in as many ways as I fancy.

@JPRuskin
JPRuskin / Convert-ControlSaveFiles.ps1
Last active August 28, 2020 13:57
A quick script to copy Remedy's Control saves from Epic's save location to Steam.
<#
.Synopsis
Copies save data from the EGS version of Remedy's Control to Steam's save location.
.Description
Old save files appear to be in a file structure similar to:
%LocalAppData%\Remedy\Control\Default-Epic-User\savegame-slot-00\global.chunk
Save files for the Steam version seem to be in the format:
Steam\userdata\<user-id>\870780\remote\savegame-slot-00_global (no extension)
@JPRuskin
JPRuskin / AzureLogContainerCreation.ps1
Created May 29, 2020 08:54
Functions to create immutable containers in Azure, for the purpose of log storage
function Add-AzStorageAccount {
<#
.Synopsis
This function creates a standardised storage account in the ResourceGroupName
.Example
Add-QmAzStorageAccount -ResourceGroupName AUSC1-FRG -Name ausc1frgdiagag3249b -Location "uscentral"
#>
[CmdletBinding()]
param(
@JPRuskin
JPRuskin / AzRestBuildHelper.psd1
Created April 21, 2020 14:40
Quick Azure DevOps REST API build helper stuff
@{
ModuleVersion = '0.1.0'
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
)
# Exports. Populated by Optimize-Module during the build step.
# For best performance, do not use wildcards and do not delete these entry!