Skip to content

Instantly share code, notes, and snippets.

@chadmando
chadmando / CeilingFan.ps1
Created May 14, 2024 16:22 — forked from dfinke/CeilingFan.ps1
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
<#
Allow an object to alter its behavior when its internal state changes.
The object will appear to change its class.
The State pattern puts each branch of the conditional in a separate class.
This lets you treat the object's state as an object in its own right
that can vary independently from other objects
#>
@chadmando
chadmando / Get-AzureADPSPermissions.ps1
Created February 21, 2024 04:01 — forked from psignoret/Get-AzureADPSPermissions.ps1
Script to list all delegated permissions and application permissions in Azure AD
<#
.SYNOPSIS
Lists delegated permissions (OAuth2PermissionGrants) and application permissions (AppRoleAssignments).
.PARAMETER DelegatedPermissions
If set, will return delegated permissions. If neither this switch nor the ApplicationPermissions switch is set,
both application and delegated permissions will be returned.
.PARAMETER ApplicationPermissions
If set, will return application permissions. If neither this switch nor the DelegatedPermissions switch is set,
@chadmando
chadmando / searchWingetLogs.ps1
Created August 21, 2023 18:11 — forked from mavaddat/searchWingetLogs.ps1
PowerShell Core function to search Winget (aka Windows Package Manager) logs
#Requires -Version 6.0
<#
.SYNOPSIS
Retrieves recent winget logs and searches them for a pattern, if specified.
.DESCRIPTION
This script parses the Windows Package Manager winget command-line tool log files and allows searching by specifying a pattern or date boundaries.
.PARAMETER Search
The pattern to search for in the log files. If not specified, all log entries are returned.
.PARAMETER AfterDate
The date after which to search for log entries. If not specified, all log entries are returned.
@chadmando
chadmando / InstallSoftware.ps1
Last active July 16, 2023 20:59 — forked from dougwaldron/InstallSoftware.ps1
Install software with winget / automate installation with PowerShell
# 1. Make sure the Microsoft App Installer is installed:
# https://www.microsoft.com/en-us/p/app-installer/9nblggh4nns1
# 2. Edit the list of apps to install.
# 3. Run this script as administrator.
Write-Output "Installing Apps"
$apps = @(
@{name = "7zip.7zip" },
@{name = "Docker.DockerDesktop"},
@{name = "Dropbox.Dropbox" },
@chadmando
chadmando / New-EXOPSSession.ps1
Created September 20, 2022 19:05 — forked from jborean93/New-EXOPSSession.ps1
Cross platform function that can connect to Exchange Online using modern auth
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
#Requires -Module MSAL.PS
Function New-EXOPSSession {
<#
.SYNOPSIS
Will open a PSSession to Exchange Online.
@chadmando
chadmando / About Batch and PowerShell.md
Created June 21, 2022 18:35 — forked from Jaykul/About Batch and PowerShell.md
Executable PowerShell (wrap a ps1 and name it cmd)

This is always my answer to all those "compile your .ps1" solutions that are floating around. Why would you wrap your PowerShell in an exe and some custom host?

Just paste this header on the top of your PowerShell script, and then before you share it, rename it with the .cmd extension. While you're writing, it's a nice syntax-highlighted PowerShell script, and when you rename it, *poof* it's double-clickable. Drop it in the PATH and you can execute it from the Run dialog or from PowerShell, batch, whatever.

Because there are still people around who actually use CMD, I've updated it to show how to handle passing parameters.

A couple of notes:

  1. It runs with ExecutionPolicy unrestricted because if you're still using CMD you probably haven't configured your ExecutionPolicy
  2. It uses -NoProfile to make sure the environment is the same on everyone's PC...
  3. It only creates function :: {} because that allows us to ignore the :: on the first line
@chadmando
chadmando / SimulateInternetZoneTest.ps1
Created April 20, 2022 19:06 — forked from mgraeber-rc/SimulateInternetZoneTest.ps1
Example highlighting why attackers likely choose ISO/IMG as a delivery mechanism - it evades SmartScreen because Mark-of-the-Web (MOTW) cannot be applied to non NTFS volumes
Add-Type -OutputAssembly hello.exe -TypeDefinition @'
using System;
public class Hello {
public static void Main(string[] Args) {
System.Console.WriteLine("Hello, world!");
System.Console.Read();
}
}
'@
@chadmando
chadmando / Test-SelectStringExamples.ps1
Created April 12, 2022 20:50 — forked from markwragg/Test-SelectStringExamples.ps1
Powershell uses of Select-String to filter a log file and example Regular Expressions for identifying IP addresses and IP spaces
#This regex matches anything that's like an IP address (even invalid ones)
$regexIPAddress = '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
#This regex matches anything like an IP address that starts 10, 172 or 192
$regexIPSpace = '(10|172|192).\d{1,3}\.\d{1,3}\.\d{1,3}\b'
#Returns the first IP address in each line of the log file/s then sorts and removes duplicates.
Select-String -Path *.log -Pattern $regexIPAddress | ForEach-Object { $_.Matches } | % { $_.Value } | Sort-Object -Unique | Out-File 'UniqueIPs.txt'
#Returns from a selection of Log files any lines which match a certain string pattern
@chadmando
chadmando / powershell-web-server.ps1
Created February 28, 2022 22:30 — forked from 19WAS85/powershell-web-server.ps1
A simple web server built with powershell.
# This is a super **SIMPLE** example of how to create a very basic powershell webserver
# 2019-05-18 UPDATE — Created by me and and evalued by @jakobii and the comunity.
# Http Server
$http = [System.Net.HttpListener]::new()
# Hostname and port to listen on
$http.Prefixes.Add("http://localhost:8080/")
# Start the Http Server
@chadmando
chadmando / brew-install-script.sh
Last active September 17, 2021 17:33 — forked from CliffordAnderson/brew-install-script.sh
Brew script for installing packages and applications on OSX
#!/bin/sh
# Homebrew Script for OSX
# To execute: save and `chmod +x ./brew-install-script.sh` then `./brew-install-script.sh`
echo "Installing brew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing brew cask..."
brew tap homebrew/cask