Skip to content

Instantly share code, notes, and snippets.

View nickadam's full-sized avatar

Nick Vissari nickadam

View GitHub Profile
@nickadam
nickadam / ConvertTo-RawDataEmail.ps1
Created April 25, 2022 13:37
Format raw data email message for sending attachments with AWS Send-SES2Email
function ConvertTo-RawDataEmail {
<#
.SYNOPSIS
Format an email message for AWS Send-SES2Email -Raw_Data
.DESCRIPTION
Accepts From, To, Cc, Bcc, Subject, Body, and Attachments, uses
System.Net.Mail to format the message into a byte array that
Send-SES2Email -Raw_Data can accept.
.PARAMETER From
[String] Sender's email address
@nickadam
nickadam / Rijndael256.ps1
Created April 2, 2022 14:10
Decrypt Rijndael 256 blocks in PowerShell Core with BouncyCastle
$Key = "SomeKey"
$IV = "SomeIV"
$CipherText = "eeXS+8jW/xrgFFeWdykzm0t8F6pmbuQwjU2uLfqJA+KyLaozbzkJ5zkpzmREA2XevE87kJXaisRDFJNeXkg+Lw=="
# Base64 CipherText to ByteArray
$CipherBytes = [System.Convert]::FromBase64String($CipherText) -As [byte[]]
# Get the Bytes of the Key and IV
$KeyBytes = [System.Text.Encoding]::UTF8.GetBytes($Key)
$IvBytes = [System.Text.Encoding]::UTF8.GetBytes($Iv)
@nickadam
nickadam / install_local_powershell_module_example.ps1
Created January 28, 2022 19:33
Install a powershell module locally
# Make a local repository to "publish" and "install" from
$PSRepository = (Join-Path -Path $HOME -ChildPath 'PSRepository')
mkdir $PSRepository
Register-PSRepository -Name 'local' -SourceLocation $PSRepository -PublishLocation $PSRepository -InstallationPolicy Trusted
# Make a module
mkdir .\MyModule
New-Item .\MyModule\Mine.psm1
New-ModuleManifest .\MyModule\Mine.psd1 -RootModule Mine.psm1 -Description 'MyModule'
@nickadam
nickadam / include_files_powershell_lambda.md
Last active February 16, 2022 12:30
Include arbitrary files in a PowerShell lambda

Include arbitrary files in a PowerShell lambda

Prerequisites

  • powershell core
  • aws cli
  • Install-Module AWSLambdaPSCore -Scope CurrentUser
  • Install-Module -Name AWS.Tools.Installer -Scope CurrentUser (only if using AWS modules)
  • Install-AWSToolsModule -Name Common (only if using AWS modules)
  • lambda execution role
@nickadam
nickadam / Install-Salt-Minion.ps1
Created December 19, 2021 00:20
Download and install salt-minion on windows
function Install-SaltClient(){
$FolderPath = "C:\ProgramData\SaltClient"
$FileName = "Salt-Minion-3004-2-Py3-AMD64.msi"
$Installer = $FolderPath + "\" + $FileName
$URL = "https://mywebserver.example.com/public/" + $FileName
$Hash = "11DE07BA38CA2B65B168237CA2485B1983A151528242C7BF81EC04A94660C0E8"
$SaltMaster = "mysaltmaster.example.com"
# Make Folder for tracking install
if(-not (Test-Path $FolderPath)){
@nickadam
nickadam / check_google_urls.js
Created December 9, 2021 18:25
Login to google workspace and check if links in csv are accessible
'use strict'
const fs = require('fs')
const puppeteer = require('puppeteer')
const parse = require('csv-parse')
const import_csv = file => {
return new Promise((resolve, reject) => {
const parser = parse({}, (err , data) => {
@nickadam
nickadam / BreachNotificationModule.ps1
Last active January 26, 2023 23:18
Send breach notifications to AD Users that have not changed their password since a breach was reported
function Find-EnabledADUser(){
<#
.SYNOPSIS
Finds a single enabled AD user for a given email address
.DESCRIPTION
Searches through the default domain or each domain given in ADDomains for a single enabled user. The user could match on EmailAddress ProxyAddresses or SamAccountName. Warns if no results or more that one result per email address.
.EXAMPLE
Find-EnabledADUser -ADDomains "example.com", "child.example.com" -Email "bob@example.com"
#>
Param(
@nickadam
nickadam / Get-MessageTraceAll.ps1
Created August 5, 2021 13:45
Get all message trace results using page feature between two dates
function Get-MessageTraceAll {
param($StartDate, $EndDate)
$Page = 1
$PageSize = 5000
$Messages = Get-MessageTrace -PageSize $PageSize -Page $Page -StartDate $StartDate -EndDate $EndDate
$Messages
while(($Messages | measure).count -gt 0){
$Page++
$Messages = Get-MessageTrace -PageSize $PageSize -Page $Page -StartDate $StartDate -EndDate $EndDate
$Messages
@nickadam
nickadam / create_keypair.sh
Created July 29, 2021 17:35
Create self-signed keypair with no prompts, 2048, 15 years
#!/bin/bash
name=$1
if [ -z $name ]
then
name="self-signed"
fi
openssl req -x509 -days 5479 -nodes -newkey rsa:2048 -keyout $name.key -out $name.pem -config <( cat << EOF
[ req ]
default_bits = 2048
@nickadam
nickadam / list_alwayson.bat
Created July 21, 2021 11:51
List XML of installed Always ON VPN profiles, must be run as SYSTEM
powershell -command "& {$nodeCSPURI = './Vendor/MSFT/VPNv2';$namespaceName = 'root\cimv2\mdm\dmmap';$className = 'MDM_VPNv2_01';$session = New-CimSession; $listInstances = $session.EnumerateInstances($namespaceName, $className, $options); foreach ($listInstance in $listInstances) { $listInstance.ProfileXML }}"