Skip to content

Instantly share code, notes, and snippets.

@FriedrichWeinmann
Created October 2, 2019 19:06
Show Gist options
  • Save FriedrichWeinmann/6598691086eba074408588693643c854 to your computer and use it in GitHub Desktop.
Save FriedrichWeinmann/6598691086eba074408588693643c854 to your computer and use it in GitHub Desktop.
The one command a P&P RPG player needs from PowerShell
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param (
[string]
$CommandName,
[System.Management.Automation.CommandLookupEventArgs]
$Lookup
)
if ($CommandName -match '^(\d+)[WD](\d+)$')
{
$Lookup.StopSearch = $true
$Lookup.Command = (Get-Command Invoke-DiceRoll)
$Lookup.CommandScriptBlock = [scriptblock]::Create("Invoke-DiceRoll -Count $($matches[1]) -Size $($matches[2])")
}
}
function Invoke-DiceRoll
{
[CmdletBinding()]
param (
[int]
$Count = 1,
[int]
$Size = 20
)
$results = foreach ($number in (1 .. $Count))
{
1..$Size | Get-Random
}
($results | Measure-Object -Sum).Sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment