Skip to content

Instantly share code, notes, and snippets.

View vexx32's full-sized avatar
💜
Turn your faults into faultlore and share them with the world.

Rain Sallow (/u/ta11ow) vexx32

💜
Turn your faults into faultlore and share them with the world.
View GitHub Profile
Get-Content -Path $File | ForEach-Object {
if ($_ -match '(?<MethodName>\w+)\((<Arguments>.*?)\) *(?={)') {
$matches['Method'] = $matches[0]
$matches.Remove(0)
[PSCustomObject]$matches
}
}
namespace PSFSharp
open System.Management.Automation
open System.Management.Automation.Internal
[<Cmdlet(VerbsLifecycle.Invoke, "ConditionalAction",
ConfirmImpact = ConfirmImpact.Medium, SupportsShouldProcess = true)>]
[<Alias("?!")>]
type InvokeConditionalActionCommand() =
inherit PSCmdlet()
function prompt {
$Success = $?
$ConsoleWidth = ($host.UI.RawUI.WindowSize.Width, $Host.UI.RawUI.BufferSize.Width -gt 0)[0]
$Escape = "`e["
$EndEscape = "m"
$Slash = [IO.Path]::DirectorySeparatorChar
$Path = $ExecutionContext.SessionState.Path.CurrentLocation
$CurrentFolder = Split-Path -Path $Path -Leaf
$Host.UI.RawUI.WindowTitle = "PS $Path"
function Invoke-SqlSelect {
<#
.DESCRIPTION
This is a re-usable function that makes a connection to the database and retrieves a result set.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string]
$Command,
# Simple approach - let PS's type conversion logic handle it.
# Pitfall: someone can just supply arbitrary text to the function, which is a bit unfortunate.
function Get-Factorial {
param($Number)
if ($Number -eq 0) {
1
}
else {
$Number = 11
$Property = [PSNoteProperty]::new("IsNumber", $true)
$Number.PSObject.Properties.Add($Property)
$Number # Gives back 11, as you'd expect
$Number | Format-List -Force # shows the hidden property
#Bonus: ScriptProperties can use $this to refer to the object they're attached to
$Number = 7
$AnotherNumber = 42
$PrimeNode = nslookup dockerhost.mycorp.com 192.168.31.67 |
Select-String -Pattern Address |
Where-Object LineNumber -eq 5 |
ForEach-Object { $_.Line.Split(' ')[-1] }
$SshData = ssh -q docker@$PrimeNode "cat /dns/zones/db.192.168.169" |
Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
$IPList = $SshData -split '; ' | Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
#Requires -Modules ThreadJob
using namespace System.Collections.Generic
function Invoke-AutoCrop {
<#
.SYNOPSIS
Uses the Python AutoCrop tool to crop images down to faces found in the image.
.DESCRIPTION
Using the AutoCrop tool, images are stripped down to just detected faces and either saved over the original
$LiveCred = Get-Credential
$Results = Invoke-Command -ComputerName ComputerA -ScriptBlock {
[PSCustomObject]@{
IP = Get-NetIPConfiguration |
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -ne "Disconnected" } |
ForEach-Object {
$_.IPv4Address.IPAddress
}
LastBoot = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
function Test-PasswordLeaked {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[PSCredential]
$Credential
)
begin {
$SHA1 = [System.Security.Cryptography.SHA1Managed]::new()
}