Skip to content

Instantly share code, notes, and snippets.

View JustinGrote's full-sized avatar

Justin Grote JustinGrote

View GitHub Profile
@JustinGrote
JustinGrote / README.MD
Last active September 6, 2024 04:02
A proxy for Format-Table to apply the resultant view or save it as a format definition

TypeFormat

This module provides an improved Format-Table that lets you persist the resultant Format-Table view either to the current session or to a .ps1xml formatting file.

This module requires PowerShell 7.2+, however the generated XML format files can be used with earlier versions.

Quick Start

PS> Get-Date
@JustinGrote
JustinGrote / settings.jsonc
Created February 22, 2023 21:12
Enable Intellisense for .csproj files in Visual Studio Code
//NOTE: Your .csproj file MUST have a dummy <Target Name='MakeSchemaHappy' /> to satisfy the schema or you will get an error
{
"xml.fileAssociations": [
{
"pattern": "**/*.csproj",
"systemId": "https://raw.githubusercontent.com/dotnet/msbuild/main/src/MSBuild/Microsoft.Build.xsd"
}
],
"xml.validation.namespaces.enabled": "onNamespaceEncountered"
}
@JustinGrote
JustinGrote / TestICMP.csproj
Last active February 14, 2023 18:10
Async Pinger Powershell Cmdlet in C#
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="7.3.2" PrivateAssets="all" />
@JustinGrote
JustinGrote / Get-MgServicePrincipalPermission.ps1
Last active November 6, 2024 10:21
Get a list of application and delegated permissions for a service principal, similar to what the Azure Portal shows
#requires -version 7 -module Microsoft.Graph.Applications
using namespace Microsoft.Graph.PowerShell.Models
using namespace System.Collections.Generic
enum MicrosoftGraphServicePrincipalType {
Application
Delegated
}
class MgServicePrincipalPermission {
@JustinGrote
JustinGrote / Sync-PrivateDnsZone.ps1
Created November 10, 2022 18:26
Copy all A records from one Private DNS zone to another (or multiple)
using namespace Microsoft.Azure.Commands.PrivateDns.Models
filter Sync-AzPrivateDnsZone {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
#The zone to copy A records from
[Parameter(Mandatory)][PSPrivateDNSZone]$SyncFrom,
#The zone to copy A records into
[Parameter(Mandatory, ValueFromPipeline)][PSPrivateDNSZone]$SyncTo,
#How fast to create records
[int]$ThrottleLimit = 10
@JustinGrote
JustinGrote / ThrowStdOutErrors.ps1
Created November 4, 2022 17:40
Catch only specific errors coming from native commands
filter ThrowStdOutErrors($messageFilter,[Parameter(ValueFromPipeline)]$obj) {
if ($obj -is [Management.Automation.ErrorRecord]) {
if ($obj -match $messageFilter) {
throw $obj
} else {
Write-Error $obj
return
}
}
$obj
@JustinGrote
JustinGrote / Find-LatestPackagesWithDependencies.ps1
Last active November 2, 2022 20:54
Get the latest version of all packages from a nuget feed that have dependencies
$items = 0..26 | ForEach-Object -ThrottleLimit 30 -Parallel {
$return = Invoke-RestMethod -Verbose "https://www.powershellgallery.com/api/v2/Packages()?`$filter=IsLatestVersion eq true and Dependencies%20gt%20%27a%27&`$select=Dependencies,Version,NormalizedVersion&`$orderby=Created%20desc&`$top=50000&`$skip=$($PSItem*100)"
$return | ForEach-Object {
[PSCustomObject]@{
Name = $_.title.'#text'
Dependency = $_.Properties.Dependencies
Version = $_.Properties.Version
NormalizedVersion = $_.Properties.NormalizedVersion
}
}
@JustinGrote
JustinGrote / Get-JAzRouteTableSummary.ps1
Created September 29, 2022 14:15
Fetch all routes for all Azure subnets that have a route table attached
using namespace Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription
using namespace Microsoft.Azure.Management.Internal.Resources.Utilities.Models
param(
$Subscriptions = $(Get-AzSubscription)
)
$Subscriptions
| Where-Object State -ne 'Disabled'
| ForEach-Object {
$context = Select-AzSubscription -SubscriptionID $PSItem.Id
@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 / FilterExample.psm1
Last active August 19, 2024 19:16
Example of Filter to convert a ForEach
#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