Draw Lottery Numbers With Get-Random
Pick a set of unique random numbers and sort them.
Run 1..49 | Get-Random -Count 6 | Sort-Object to draw six unique numbers.
01Command
Command
$ 1..49 | Get-Random -Count 6 | Sort-Object02What 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
!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-RandomEvidence: Documents -Count, which selects unique random items from a pipeline.
Last verified: 2026-09-20 · Category: Developer
06Related solutions
Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.
Zip Files with Compress-Archive
Create or update a .zip from any files or folder contents straight from PowerShell.
Test a TCP port connection on Windows with Test-NetConnection
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.