Draw Lottery Numbers With Get-Random

Pick a set of unique random numbers and sort them.

WindowsrandomscriptingpowershellLow risk
Run 1..49 | Get-Random -Count 6 | Sort-Object to draw six unique numbers.

01Command

Command
$ 1..49 | Get-Random -Count 6 | Sort-Object

02What it does

Piping a range into Get-Random with -Count selects that many distinct items without replacement, so no number repeats. Sort-Object then orders them for display. Change the range or count for other lotteries and raffles.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: This is fine for casual raffles but not for cryptographic draws where fairness must be provable.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Get-Random
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Documents -Count, which selects unique random items from a pipeline.

Last verified: 2026-09-20 · Category: Developer

06Related solutions