Skip to content

Instantly share code, notes, and snippets.


Justin Grote JustinGrote

View GitHub Profile
JustinGrote / StartVSCodeServer.ps1
Last active Aug 9, 2022
Powershell Bootstrap script for VSCode Server
View StartVSCodeServer.ps1
#require -version 5.1
#Usage: iwr | iex
#Parameterized usage: & ([ScriptBlock]::Create((iwr -Your -Options
#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
#Installation architecture. This is normally autodetected.
#Installation platform. Normally autodetected.
$Target = 'unknown-linux-gnu',
JustinGrote / FilterExample.psm1
Last active Jul 22, 2022
Example of Filter to convert a ForEach
View FilterExample.psm1
#Filter is just a function with the process{}
#block as the default rather than end{}. That's it, it's not scary.
# $y = 1..3
# foreach ($x in $y) {
# "This is item $x"
# }
# #Result:
# #This is item 1
JustinGrote / IncorrectUseOfFormatCmdletsInMiddleOfPipeline.psm1
Last active Jul 18, 2022
Warn if Format command (Format-Table, etc.) are used in the middle of a pipeline.
View IncorrectUseOfFormatCmdletsInMiddleOfPipeline.psm1
using namespace System.Management.Automation.Language
using namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
function IncorrectUseOfFormatCmdletsInMiddleOfPipeline {
Do not place format-table in the middle of a pipeline
Detects when Format commands are commonly misused in the middle of a pipeline, causing unexpected results with display objects that dont have the same properties as the original piped object.
JustinGrote / install-powershell.ps1
Last active Jul 9, 2022
PowerShell Bootstrap Script
View install-powershell.ps1
Install PowerShell on Windows, Linux or macOS.
#Where PowerShell should be installed.
#The version to install. Default is the latest stable version. Additional Options are a LTS, Preview, Daily, or a specific version number tag.
[ValidateNotNullOrEmpty][string]$Version = 'Stable'
JustinGrote / Add-JAzADServicePrincipalRole.ps1
Created Jul 8, 2022
Add a Role to a SAML-only Enterprise Application that you can then provide as a claim for user assignment (there is no GUI for this)
View Add-JAzADServicePrincipalRole.ps1
using namespace Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10
using namespace System.Management.Automation
using namespace System.Collections.Generic
function Add-JAzADServicePrincipalRole {
[CmdletBinding(DefaultParameterSetName='ByObject', SupportsShouldProcess)]
#The display name of the role. This is the name that will be displayed in the app portal when assigning the role to a user or group.
#The value that will be added to the SAML roles claim for the user. Make this something that is appropriate to signal to your application what role the user should have, e.g. admin, owner, etc., your App may have specific documentation for this effect, for example Palo Alto defines specific values like superuser and superreader
JustinGrote / PowerShellModuleTemplateProvider.class.ps1
Created Jul 8, 2022
Implementing a Microsoft .NET Template Engine Package Provider as a Powershell Class - Just because you can doesn't mean you should
View PowerShellModuleTemplateProvider.class.ps1
using namespace System
using namespace System.Collections.Generic
using namespace System.Threading
using namespace System.Threading.Tasks
using namespace Microsoft.TemplateEngine.Abstractions
using namespace Microsoft.TemplateEngine.Abstractions.TemplatePackage
class PowerShellModuleTemplatePackageProvider : ITemplatePackageProvider {
JustinGrote / Get-ParamBlock.ps1
Created Jul 7, 2022
Get a hashtable of the parameters in your param block, useful for splatting.
View Get-ParamBlock.ps1
using namespace system.collections.generic
function Get-ParamBlock ([String[]]$Name) {
[hashset[string]]$params = $PSCmdlet.MyInvocation.MyCommand.Parameters.Keys
$params.ExceptWith([string[]]([PSCmdlet]::CommonParameters + [PSCmdlet]::OptionalCommonParameters))
$result = @{}
if ($Name) {$params = $params -in $Name}
foreach ($name in $params) {
$result.$name = $PSCmdlet.GetVariableValue($name)
return $result
JustinGrote / Write-FunctionError.ps1
Last active Jul 6, 2022
Write an Error within a function in a nice way that displays the context of the function rather than the "Write-Error" context
View Write-FunctionError.ps1
using namespace System.Management.Automation
using namespace Microsoft.PowerShell.Commands
function Write-FunctionError {
Writes an error within the context of the containing CmdletBinding() function. Makes errr displays prettier
[ValidateNotNullOrEmpty()][ErrorCategory]$Category = 'WriteError',
JustinGrote / Receive-Task.ps1
Last active Jul 5, 2022
"Await" one or more tasks in PowerShell in a cancellable manner (e.g. ctrl-c still works)
View Receive-Task.ps1
using namespace System.Threading.Tasks
using namespace System.Collections.Generic
filter Receive-Task {
#Wait on one or more tasks in a cancellable manner
[parameter(Mandatory, ValueFromPipeline)][Task]$Task,
#How long to wait before checking for a cancellation in milliseconds
[int]$WaitInterval = 500
View oh-my-posh.yaml
# yaml-language-server: $schema=
- alignment: left
newline: true
- type: path
background: '#333333'
foreground: '#CCCCCC'