-
PowerShell 2.0: One Cmdlet at a Time #1 Get-Random
Posted on November 12th, 2009 2 commentsThis is the first of a series looking at new cmdlets available in PowerShell 2.0. We begin by looking at the Get-Random cmdlet.
What can I do with it?
With Get-Random you can either generate a random number, or randomly select objects from a collection.
Examples:
Generate a random number between 1 and 100.
Get-Random -Minimum 1 -Maximum 101
Select a random object from a collection
$users = 'Rod','Jane','Freddy' Get-Random $users
Select a random Windows Service
Get-Service | Get-Random
How could I have done this in PowerShell 1.0?
Generate a random number between 1 and 100 using .NET.
$randomnumber = New-Object System.Random $randomnumber.next(1,101)
Select a random object from a collection
$users = 'Rod','Jane','Freddy' $randomnumber = New-Object System.Random $i = $randomnumber.next(0,$users.length) $users[$i]
How did I decide to begin this series with Get-Random?
Get-Command | Get-Random
2 Trackbacks / Pingbacks
-
[...] Series of posts on PowerShell 2.0 from Jonathan Medd [...]
-
Episode 92 – The BSonPosh Module with MVP Brandon Shell « PowerScripting Podcast November 17th, 2009 at 05:42
[...] Jonathan Medd has started a new series: PowerShell 2.0: One Cmdlet at a Time [...]
Leave a reply
-




Weekend miscellany — The Endeavour November 13th, 2009 at 22:57