Skip to content

Instantly share code, notes, and snippets.

View JustinGrote's full-sized avatar

Justin Grote JustinGrote

View GitHub Profile
@JustinGrote
JustinGrote / Test-AzDOPipeline.ps1
Last active March 6, 2024 12:19
Test Azure Devops Pipeline YAML
function Test-AzDOPipeline {
<#
.SYNOPSIS
Tests an Azure Devops Pipeline YAML configuration
.DESCRIPTION
This can be used to validate an Azure Devops pipeline configuration within a particular pipeline project.
#>
param (
#Your Azure Devops Organization Name
@JustinGrote
JustinGrote / 2021-12-02-The-Many-Places-To-Run-Powershell-In-Azure.md
Created December 2, 2021 21:39
The Many Places to Run Powershell In Azure
title classes toc
The Many Places to run PowerShell in Azure
wide
true

Intro

PowerShell is a fantastic language not just for managing Azure and related services, but for writing entire applications. I have written applications that sync millions of tickets a month between two systems and support the automatic creation and synchronization of tens of thousands of Microsoft 365 Groups based on business rules and user attributes.

@JustinGrote
JustinGrote / StartVSCodeServer.ps1
Last active February 29, 2024 02:37
Powershell Bootstrap script for VSCode Server
#require -version 5.1
#Usage: iwr https://tinyurl.com/VSCodeServer | iex
#Parameterized usage: & ([ScriptBlock]::Create((iwr https://tinyurl.com/VSCodeServer))) -Your -Options
param(
#Path to install the vscode binary to. This defaults to a folder in your Local AppData path. Must be writable by your current user without sudo
[ValidateNotNullOrEmpty()]
[string]$InstallPath = $(Join-Path -Path ([System.Environment]::GetFolderPath('LocalApplicationData')) -ChildPath 'vscode-cli'),
#Installation architecture. This is normally autodetected.
$Arch,
$OS,
@JustinGrote
JustinGrote / ScreenConnect.psm1
Last active February 28, 2024 07:50
ScreenConnect Client
#requires -version 7
using namespace Microsoft.PowerShell.Commands
using namespace System.Text
$ErrorActionPreference = 'Stop'
#Suppress useless IRM Verbose output
$PSDefaultParameterValues['Invoke-RestMethod:Verbose'] = $false
$PSDefaultParameterValues['Invoke-WebRequest:Verbose'] = $false
$DebugPreference = 'SilentlyContinue'
@JustinGrote
JustinGrote / PowerAltoPlus.psm1
Last active February 26, 2024 17:16
An extension of the PowerAlto module to enable running "ssh" commands via RPC-XML thru panorama to managed devices without having direct line of sight to the managed firewalls. A sample report dump of the Arp/Route/Interface/VPN is included
#requires -module PowerAlto, ImportExcel
$ErrorActionPreference = 'Stop'
if (-not $MacVendorCache) {
Write-Warning 'MacVendorCache not found, downloading from maclookup.app. This is common on the first run.'
$SCRIPT:MacVendorCache = @{}
foreach ($entry in $(ConvertFrom-Csv (Invoke-RestMethod 'https://maclookup.app/downloads/csv-database/get-db'))) {
$MacVendorCache[$entry.'Mac Prefix'] = $entry.'Vendor Name'
}
}
@JustinGrote
JustinGrote / EasyFormat.ps1
Created March 9, 2023 16:40
A proxy for Format-Table to apply the resultant view or save it as a format definition
using namespace System.Management.Automation
using namespace System.Collections
function ConvertFrom-Format {
<#
.SYNOPSIS
Converts Format-Table output to a format that can be used with Add-FormatTable
#>
param(
#The name of the format view definition assigned to the format data. Default is 'CustomTableView
[ValidateNotNullOrEmpty()][string]$Name = 'CustomTableView',
@JustinGrote
JustinGrote / Get-ScriptModules.ps1
Last active February 16, 2024 15:48
Find the module names for all commands used in a script
#requires -version 7
using namespace System.Management.Automation.Language
using namespace Collections.Generic.Queue
function Get-ScriptModules {
<#
.SCRIPTBLOCK
Given a script, returns a list of all the modules it uses.
#>
@JustinGrote
JustinGrote / Get-OpenApiDefinition.ps1
Created February 15, 2024 02:40
Download multiple parts of an OpenAPI spec
using namespace System.Collections.Generic
function Get-OpenApiDefinition {
<#
Fetches the OpenAPI definition from the specified URI and for every ref, downloads the relative file to the destination folder. Currently only works with relative refs
#>
param (
#The source
[Parameter(Mandatory)]
[Uri]$Uri,
@JustinGrote
JustinGrote / MandatoryProperties.ps1
Last active February 2, 2024 06:41
A Powershell Class with Mandatory Properties by Default
using namespace System.Collections
using namespace System.Management.Automation
using namespace System.ComponentModel.DataAnnotations
using namespace System.Runtime.Serialization
class MandatoryProperties {
MandatoryProperties([IDictionary]$properties) {
$this.GetType().GetProperties([System.Reflection.BindingFlags]'Instance,Public') | ForEach-Object {
$propertyName = $PSItem.Name
[bool]$isOptional = $PSItem.GetCustomAttributes([OptionalFieldAttribute], $true).count -gt 0
if (
@JustinGrote
JustinGrote / Add-SSHTrustedHost.ps1
Last active January 26, 2024 14:48
Fetch the public keys of one or more hosts to add to the known_hosts file
function Add-SSHTrustedHost {
<#
.SYNOPSIS
Connects to a host via SSH and retrieves its public key to pre-authorize the system. Useful in automated scripts or Powershell Remoting setup
.NOTES
This is basically a wrapper around ssh-keyscan and is expected to be installed.
It has extremely basic parsing at the moment and will likely result in redundant keys if you do anything special like comma-separated names for keys
.EXAMPLE
Add-SSHTrustedHost -Hostname "Computer1","Computer2","Computer3"
Adds keys from the manually specified hosts into known_hosts