Skip to content

Instantly share code, notes, and snippets.

@Myrddraal
Myrddraal / Test-ChangesMadeInPath.ps1
Last active April 29, 2024 05:37
Skip infrastructure deployments if there are no changes to deploy (Azure Pipelines)
[CmdletBinding()]
param (
$authorisation,
$pathFilter,
$collectionUri,
$project,
$buildId
)
$changesUrl = "$collectionUri/$project/_apis/build/builds/$buildId/changes?api-version=6.0"
@JustinGrote
JustinGrote / Trace-AICommand.ps1
Last active April 9, 2024 22:25
Report the results and performance of any scriptblock to Azure Application Insights
#requires -version 7
#You can load this script with $(iwr https://tinyurl.com/TraceAICommand | iex)
using namespace Microsoft.ApplicationInsights
using namespace Microsoft.ApplicationInsights.Extensibility
using namespace Microsoft.ApplicationInsights.DataContracts
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Net
#Reference: https://docs.microsoft.com/en-us/azure/azure-monitor/app/console
@JustinGrote
JustinGrote / Get-MgServicePrincipalPermission.ps1
Last active April 3, 2024 21:56
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 {
@davefunkel
davefunkel / Script-Template-WithCreds.ps1
Last active March 11, 2024 08:49
PowerShell Script Template with Saved Creds
<#
.SYNOPSIS
The synopsis goes here. This can be one line, or many.
This version of the template has inbuilt functions to capture credentials and store it securely for reuse
Avoids the need to have plaintext passwords in the script
.DESCRIPTION
The description is usually a longer, more detailed explanation of what the script or function does.
Take as many lines as you need.
Function Out-JSONView {
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
[psobject]$InbutObject,
[int]$Depth = 2
@Tiberriver256
Tiberriver256 / PowerShellNTFSStaticFileServer.ps1
Last active January 5, 2024 08:23
This script starts a small web server listening on localhost:8080 that will impersonate the authenticated user and serve static content. This means if they do not have NTFS permissions to the file they will get an access denied or a 404 file not found if they do not have NTFS access to list contents of the directory.
function Get-DirectoryContent {
<#
.SYNOPSIS
Function to get directory content
.EXAMPLE
Get-DirectoryContent -Path "C:\" -HeaderName "poshserver.net" -RequestURL "http://poshserver.net" -SubfolderName "/"
@Jaykul
Jaykul / Mandelbrot.psm1
Last active December 26, 2023 11:41
ASCII Mandelbrots in the PowerShell console
using namespace System.Numerics
class Mandelbrot : System.Collections.IEnumerator {
# From the constructor?
# Sadly, PowerShell doesn't support optional parameters
[double]$HorizontalViewOffset = -0.5
[double]$VerticalViewOffset = 0
$Columns = 120
$Rows = 28
$ZoomViewDistance = 6.75
@rchaganti
rchaganti / downloadTerraform.ps1
Created October 13, 2020 09:18
Download and Install Terraform - Windows (PowerShell)
[CmdletBinding(DefaultParameterSetName='Version')]
param
(
[Parameter(ParameterSetName='Latest', Mandatory = $true)]
[Parameter(ParameterSetName='Version', Mandatory = $true)]
[String]
$SaveToPath,
[Parameter(ParameterSetName='Version', Mandatory = $true)]
[String]
@potatoqualitee
potatoqualitee / ZInstall-KBUpdate.ps1
Last active September 29, 2023 23:06
Installing KB Updates on Remote System, 5 day dev journal
# THIS HASN'T BEEN ADDED TO THE KBUPDATE REPO YET BUT WILL BE WHEN I GET A MOMENT
function Install-KbPatch {
<#
.SYNOPSIS
Installs KBs on local and remote servers on Windows-based systems
.DESCRIPTION
Installs KBs on local and remote servers on Windows-based systems
PowerShell 5.1 must be installed and enabled on the target machine and the target machine must be Windows-based
@JustinGrote
JustinGrote / ModuleFast.ps1
Last active July 24, 2023 16:26
Bootstrap Script for a High Performance Module Installer
using namespace System.Net.Http
#requires -version 7.2
# This is the bootstrap script for Modules
[CmdletBinding(PositionalBinding = $false)]
param (
#Specify a specific release to use, otherwise 'latest' is used
[string]$Release = 'latest',
#Specify the user
[string]$User = 'JustinGrote',
#Specify the repo