PowerShell: how to sort an Array randomly?

Ever had the need to random sort an array in PowerShell?
Sorting an array randomly is as easy as that:

1
2
3
4
5
# Creating a new array
$array = @(1..20)
 
# Sorting the array randomly 
$array | Sort-Object { Get-Random }

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.