Skip to content

Instantly share code, notes, and snippets.

@HumanEquivalentUnit
HumanEquivalentUnit / notes.dyalog
Last active December 21, 2019 13:14
PowerShell Cmdlet in Dyalog APL proof of concept
⍝ This is in a workspace, default namespace
⍝ created by )Ed ○InvokeAplExpression
⍝ Then exported as a Microsoft .Net Assembly
⍝ With the Isolation Mode dropdown set to
⍝ 'Each assembly attempts to use local bridge and interpreter libraries'
⍝ pre-req: make a project folder e.g. "D:\m\" and copy file
⍝ System.Management.Automation.dll from the .Net GAC into it.
⍝ PS> Copy-Item -Path ([psobject].Assembly.Location) -Destination 'd:\m\' -Verbose
# Parameters
param(
[string] $ComputerList = $(Join-Path -Path $PSScriptRoot -ChildPath "computers.txt"), # Path to the list of computers
[string] $ReportPath = $(Join-Path -Path $PSScriptRoot -ChildPath "report.csv"), # Path to the report to output
[switch] $DeleteFolder = $false # Whether to delete MININT or not
)
Get-Content $ComputerList | ForEach-Object {
$result = @{
@HumanEquivalentUnit
HumanEquivalentUnit / MenuTest.ps1
Created November 16, 2018 08:34
PowerShell + Windows Forms dynamic dropdown menu from filesystem example
# These are the starting folders
$documentRoots = 'C:\Users\', 'C:\Program Files\'
# Load Windows forms assemblies
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
@HumanEquivalentUnit
HumanEquivalentUnit / Test-PasswordComplexity-v3.ps1
Last active September 21, 2018 05:18
Test AD Password Complexity v3
<#
.Synopsis
Tests a string against Active Directory default password complexity requirements
.DESCRIPTION
Checks password length, and whether it meets 3 out of 4 of the following:
- Lowercase character a-z
- Uppercase character A-Z
- Digit 0-9
- Special character !,#,-, etc.
# Map URLs to Internet Explorer Security Zones via PowerShell
$csSource = @'
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
public class IEZones
{
@HumanEquivalentUnit
HumanEquivalentUnit / gist:c00db7ceb2fdba17931145e27c71b0ee
Created August 3, 2018 18:37
Bodge-add binary literal number support to PowerShell
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param($Name,[System.Management.Automation.CommandLookupEventArgs]$CommandLookupArgs)
$CommandLookupArgs.CommandScriptBlock = {
if ($CommandLookupArgs.CommandName -match '(?<binary>1[10]*)b$')
{
[convert]::ToInt32($matches['binary'], 2)
}
@HumanEquivalentUnit
HumanEquivalentUnit / Get-SslCertFromThawteApprovalEmail.ps1
Created February 7, 2018 23:04
PowerShell script to export SSL Certificate delivery emails to .crt files
# Automates Outlook
# - searches the Inbox for Thawte
# 'your SSL certificate has been approved' messages
# - extracts the certificate to disk with a useful filename
# - deletes the emails
$VerbosePreference = 'continue'
$OutputFolder = '\\server\share\SSL Cert Deliveries\'
@HumanEquivalentUnit
HumanEquivalentUnit / day15-part1.ps1
Created December 15, 2017 21:35
adventofcode powershell vs c# timings
# C# runs in ~0.5 seconds.
# powershell commented out below runs in ~23 seconds.
# correct answer is 567
Add-Type @'
using System;
public class MyType1
{
public long crunch() {
@HumanEquivalentUnit
HumanEquivalentUnit / 2017-adventofcode2.ps1
Created December 2, 2017 05:30
2017 Advent of Code - day 2
$in = @'
5 9 2 8
9 4 7 3
3 8 6 5
'@ -split "`r?`n"
$in | ForEach-Object {
# part 1 was easy, split string, measure the max and min, then find the difference
# part 1 # $minmax = -split $_ | Measure-Object -Minimum -Maximum
$in = '1212'
# Just regex out the characters which are the same as the following character, with a backreference
# convert to int, and sum them. Handle the wraparound condition by adding the first character
# to the end of the string
function day1 {
param($s)
$s = $s + $s[0]