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 / EnrollIntune.ps1
Created April 5, 2024 19:44
Device Enrollment Script for AAD Joined Machine that were not enrolled in Intune upon setup
# Intially copied from this article https://call4cloud.nl/2020/05/intune-auto-mdm-enrollment-for-devices-already-azure-ad-joined/
# "The Improved One"
# Set MDM Enrollment URL's
$key = 'SYSTEM\CurrentControlSet\Control\CloudDomainJoin\TenantInfo\*'
try{
$keyinfo = Get-Item "HKLM:\$key"
}
catch{
@chadmando
chadmando / ns-u.ps1
Created March 19, 2024 15:15
ns command for UDP connections in powershell
# Full credit for this goes to a SANS ICS diary by Rob Vandenbrink
# https://isc.sans.edu/diary/30532?n
Get-NetUDPEndpoint |
Select-Object LocalAddress,LocalPort,CreationTime,OwningProcess,@{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} |
Format-Table -auto
@chadmando
chadmando / ns-t.ps1
Created March 19, 2024 15:04
ns command written in powershell to include lifetime of established connections - TCP version
# Full credit for this goes to a SANS ICS diary by Rob Vandenbrink
# https://isc.sans.edu/diary/30532?n
$now = get-date
Get-NetTCPConnection |
select-object LocalAddress,LocalPort,RemoteAddress,RemotePort,State,@{Name="LifetimeSec";Expression={($now-$_.CreationTime).seconds}},OwningProcess, @{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} |
sort-object -property LifetimeSec |
select-object -last 10 |
ft -auto
@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 / winget_pkgs.json
Created September 12, 2023 02:35
Example result of winget export command
{
"$schema" : "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate" : "2023-09-11T21:26:35.321-00:00",
"Sources" :
[
{
"Packages" :
[
{
"PackageIdentifier" : "Docker.DockerDesktop"
@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 / getlocaladmins.bat
Created August 10, 2022 23:41
Command to query the local administrators group for member when PowerShell is broken
net localgroup adminstrators