Skip to content

Instantly share code, notes, and snippets.

💖
Stay warm

Joel Sallow (/u/ta11ow) vexx32

💖
Stay warm
Block or report user

Report or block vexx32

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View JavaMethodGrab.ps1
Get-Content -Path $File | ForEach-Object {
if ($_ -match '(?<MethodName>\w+)\((<Arguments>.*?)\) *(?={)') {
$matches['Method'] = $matches[0]
$matches.Remove(0)
[PSCustomObject]$matches
}
}
View Invoke-ConditionalAction.fs
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()
View profile.ps1
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"
View SqlSelect.ps1
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,
View factorialExample.ps1
# 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 {
View NotePropertiesExample.ps1
$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
View BashScripter62.ps1
$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}"
View Invoke-AutoCrop.ps1
#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
View invokecommand.ps1
$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
View HaveIBeenPwned.ps1
function Test-PasswordLeaked {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[PSCredential]
$Credential
)
begin {
$SHA1 = [System.Security.Cryptography.SHA1Managed]::new()
}
You can’t perform that action at this time.