Guest User

Untitled

a guest
Oct 21st, 2019
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ExecutionContext.InvokeCommand.CommandNotFoundAction = {
  2. param (
  3. [string]
  4. $CommandName,
  5.  
  6. [System.Management.Automation.CommandLookupEventArgs]
  7. $Lookup
  8. )
  9.  
  10. if ($CommandName -match '^(\d+)[WD](\d+)$')
  11. {
  12. $Lookup.StopSearch = $true
  13. $Lookup.Command = (Get-Command Invoke-DiceRoll)
  14. $Lookup.CommandScriptBlock = [scriptblock]::Create("Invoke-DiceRoll -Count $($matches[1]) -Size $($matches[2])")
  15. }
  16. }
  17.  
  18. function Invoke-DiceRoll
  19. {
  20. [CmdletBinding()]
  21. param (
  22. [int]
  23. $Count = 1,
  24.  
  25. [int]
  26. $Size = 20
  27. )
  28.  
  29. $results = foreach ($number in (1 .. $Count))
  30. {
  31. 1..$Size | Get-Random
  32. }
  33. ($results | Measure-Object -Sum).Sum
  34. }
RAW Paste Data