Skip to content

Instantly share code, notes, and snippets.

View JPRuskin's full-sized avatar

James Ruskin JPRuskin

View GitHub Profile
@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!
@JPRuskin
JPRuskin / ConvertTo-ProductKey.ps1
Last active April 5, 2020 11:51
Should output the Windows product key
function ConvertTo-ProductKey {
[CmdletBinding()]
param(
[byte[]]$Key,
[switch]$Validate
)
end {
$KeyOffset = 52
[char[]]$Chars = "BCDFGHJKMPQRTVWXY2346789"
$KeyOutput = ""
@JPRuskin
JPRuskin / Invoke-ModifiedTests.ps1
Created March 13, 2020 11:58
Gets a list of changed files in a given repository directory and runs tests that match them.
function Invoke-ModifiedTests {
<#
.Synopsis
Gets a list of changed files in a repository, and run every changed test and test matching a changed function/file
.Description
This assumes that each file has a matching .Tests.ps1 file, suited for running with Pester. It also ignores Integration tagged tests.
.Example
Invoke-ModifiedTests -Repository C:\Source\Module
using namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
function Export-PfxFromAzureKeyVault {
<#
.Synopsis
Exports a PFX file from an Azure KeyVault Certificate
.Example
Export-PfxFromAzureKeyVault -VaultName TestVault -Name TestCert -Password $SecurePW -Path C:\Temp\TestCert.pfx
#>
using namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
function Invoke-AzVMScript {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ResourceGroupCompleter()]
[string]$ResourceGroupName,
[Parameter(Mandatory)]
class fileregion {
hidden [string]$OriginalFilePath
[string]$RelativeFilePath
[int]$StartLine
[int]$EndLine
}
function Get-FileRegions {
param(
[string[]]$Path
@JPRuskin
JPRuskin / Export-Variable.ps1
Created May 3, 2019 08:19
Export and Import Variables between PowerShell sessions (naive)
# function Export-Variable {
[CmdletBinding()]
param(
[ArgumentCompleter({
param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $BoundParams)
$Current = $BoundParams.Name
(Get-Variable).Name.Where({$_ -like "*$($WordToComplete)*" -and $_ -notin $Current})
})]
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]$Name,
@JPRuskin
JPRuskin / Add-AzureModule.ps1
Last active May 29, 2019 10:24
Function/Script to add a saved module from C:\Modules, as the AzureDevOps build machines seem to. Worked into the SimpleAzureModule module.
function Add-AzureModule {
[CmdletBinding(DefaultParameterSetName="Calculated")]
param(
[Parameter(ParameterSetName="Calculated", Position=0)]
[ArgumentCompleter({
param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $BoundParams)
(Get-ChildItem C:\Modules\).Where({$_ -like "*$WordToComplete*_*"}).Name | %{$_.Split('_')[0]} | Sort-Object -Unique
})]
[string]$Name,
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Arduino for Badgey",
"type": "process",
"command": "echo No idea, sorry",
"windows": {