๐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$string = 'hostname.database.table.schema' | |
if ($string -match '(?<Hostname>\w+)\.(?<Database>\w+)\.(?<Table>\w+)\.(?<Schema>\w+)') { | |
$matches.Remove(0) | |
[PSCustomObject]$matches | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Content -Path $File | ForEach-Object { | |
if ($_ -match '(?<MethodName>\w+)\((<Arguments>.*?)\) *(?={)') { | |
$matches['Method'] = $matches[0] | |
$matches.Remove(0) | |
[PSCustomObject]$matches | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |