{"id":6281,"date":"2008-04-27T13:07:00","date_gmt":"2008-04-27T13:07:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/04\/27\/get-random\/"},"modified":"2019-02-18T13:16:00","modified_gmt":"2019-02-18T20:16:00","slug":"get-random","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/get-random\/","title":{"rendered":"Get-Random"},"content":{"rendered":"<p>I saw <a href=\"http:\/\/web2.minasi.com\/forum\/topic.asp?TOPIC_ID=26736\"><font color=\"#669966\">THIS<\/font><\/a> posting over on Mark Minasi&#8217;s forums that caught my eye.&nbsp; It gives you a random help file under the motto of: &#8220;A powershell help file a day, keeps Don Jones away&#8221;.&nbsp; \ud83d\ude42<\/p>\n<p>Don responded pointing out one of our new V2 cmdlets:&nbsp; Get-Random.&nbsp; Since that cat is out of the bag and Get-Random is so cool, let&#8217;s explore it:<\/p>\n<p>PS&gt;<strong>Get-Help Get-Random<\/strong><\/p>\n<p>NAME<br \/>&nbsp;&nbsp;&nbsp; Get-Random<\/p>\n<p>SYNOPSIS<br \/>&nbsp;&nbsp;&nbsp; Gets a random number or selects objects randomly from a collection.<\/p>\n<p>SYNTAX<br \/>&nbsp;&nbsp;&nbsp; Get-Random [-Count [&lt;Uint32&gt;]] [[-InputObject] [&lt;psobject&gt;]] [-SetSeed [&lt;in<br \/>&nbsp;&nbsp;&nbsp; t&gt;]] [&lt;CommonParameters&gt;]<\/p>\n<p>&nbsp;&nbsp;&nbsp; Get-Random [-Minimum [&lt;Object&gt;]] [[-Maximum] [&lt;Object&gt;]] [-SetSeed [&lt;int&gt;]]<br \/>&nbsp;&nbsp;&nbsp;&nbsp; [&lt;CommonParameters&gt;]<\/p>\n<p>DETAILED DESCRIPTION<br \/>&nbsp;&nbsp;&nbsp; The Get-Random cmdlet gets a randomly selected number. If you submit a coll<br \/>&nbsp;&nbsp;&nbsp; ection of objects to Get-Random, it gets one or more randomly selected obje<br \/>&nbsp;&nbsp;&nbsp; cts from the collection.<\/p>\n<p>&nbsp;&nbsp;&nbsp; Without parameters or input, &#8220;Get-Random&#8221; returns a randomly selected 32-bi<br \/>&nbsp;&nbsp;&nbsp; t unsigned integer between 0 and Int32.MaxValue (0x7FFFFFFF, 2,147,483,647)<br \/>&nbsp;&nbsp;&nbsp; .<\/p>\n<p>&nbsp;&nbsp;&nbsp; You can use the parameters of Get-Random to specify a seed number, minimum<br \/>&nbsp;&nbsp;&nbsp; and maximum values, and the number of objects returned from a submitted col<br \/>&nbsp;&nbsp;&nbsp; lection.<\/p>\n<p>RELATED LINKS<\/p>\n<p>REMARKS<br \/>&nbsp;&nbsp;&nbsp; For more information, type: &#8220;get-help Get-Random -detailed&#8221;.<br \/>&nbsp;&nbsp;&nbsp; For technical information, type: &#8220;get-help Get-Random -full&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p>PS&gt; <strong># Get A random number<br \/><\/strong>PS&gt; <strong>Get-Random<\/strong><br \/>1163375074<br \/>PS&gt;<br \/>PS&gt; <strong># Get a random number within a range<br \/><\/strong>PS&gt; <strong>Get-Random -min 10 -max 15<br \/><\/strong>13<br \/>PS&gt;<br \/>PS&gt; <strong># Get a random element<\/strong><br \/>PS&gt; <strong>&#8220;Tom&#8221;,&#8221;Dick&#8221;,&#8221;Harry&#8221; |Get-Random<br \/><\/strong>Dick<br \/>PS&gt; <strong># Get a set of random elements<br \/><\/strong>PS&gt; <strong>&#8220;Tom&#8221;,&#8221;Dick&#8221;,&#8221;Harry&#8221; |Get-Random -count 3<br \/><\/strong>Tom<br \/>Harry<br \/>Dick<br \/>PS&gt; <strong># Is it really random?&nbsp; yup<br \/><\/strong>PS&gt; <strong>&#8220;Tom&#8221;,&#8221;Dick&#8221;,&#8221;Harry&#8221; |Get-Random -count 3<br \/><\/strong>Dick<br \/>Harry<br \/>Tom<br \/>PS&gt; <strong># It works with any set of objects<br \/><\/strong>PS&gt; <strong>gps |get-Random -Count 2<\/strong><\/p>\n<p>Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS(K) VM(M)&nbsp;&nbsp; CPU(s)&nbsp;&nbsp;&nbsp;&nbsp; Id ProcessName<br \/>&#8212;&#8212;-&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; &#8212;&#8211;&nbsp;&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212; &#8212;&#8212;&#8212;&#8211;<br \/>&nbsp;&nbsp;&nbsp; 361&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 26&nbsp;&nbsp;&nbsp; 51316&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55864&nbsp;&nbsp; 151&nbsp;&nbsp; 225.73&nbsp;&nbsp; 1700 svchost<br \/>&nbsp;&nbsp; 1570&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16&nbsp;&nbsp;&nbsp; 68756&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 30300&nbsp;&nbsp; 276&nbsp;&nbsp; 457.43&nbsp;&nbsp; 2424 SearchIndexer<\/p>\n<p>PS&gt; <strong>gps |get-Random -Count 2<\/strong><\/p>\n<p>Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS(K) VM(M)&nbsp;&nbsp; CPU(s)&nbsp;&nbsp;&nbsp;&nbsp; Id ProcessName<br \/>&#8212;&#8212;-&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; &#8212;&#8211;&nbsp;&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212; &#8212;&#8212;&#8212;&#8211;<br \/>&nbsp;&nbsp;&nbsp; 316&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp; 3004&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7368&nbsp;&nbsp;&nbsp; 40&nbsp;&nbsp;&nbsp; 36.61&nbsp;&nbsp;&nbsp; 604 services<br \/>&nbsp;&nbsp;&nbsp; 209&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9&nbsp;&nbsp;&nbsp; 75740&nbsp;&nbsp;&nbsp;&nbsp; 137232&nbsp;&nbsp; 197 1,067.36&nbsp;&nbsp; 2760 dwm<\/p>\n<p>&nbsp;<\/p>\n<p>At the end of the day, the cmdlets that manage the OS features need to come from those feature teams so you should not expect PowerShell to deliver a ton of those.&nbsp; For instance, the AD team needs to deliver the AD cmdlets, the network team needs to deliver networking Cmdlets.&nbsp; If you are not getting the cmdlets you need, you should knock on the doors of those feature teams.&nbsp; Don&#8217;t suffer in silence, complain. <\/p>\n<p>PowerShell will deliver some management cmdlets but by and large, we are going to focus our efforts on utility cmdlets that work against anyones objects and make it a good deal for those feature teams to develop cmdlets.&nbsp; Get-Random is just such a cmdlet.&nbsp; I&#8217;ll bet you a dollar to a doughnut that no feature team would ever prioritize Get-Random but it turns out that all of their customers will use it at some point.&nbsp; PowerShell delivers it and thus the feature team&#8217;s customers benefit.&nbsp; That&#8217;s the deal &#8211; you invest in writting cmdlets\/providers and we invest in ensuring that that was a great investement by delivering a ton of functions to your customers.&nbsp; How can you go wrong with that?<\/p>\n<p>Enjoy!&nbsp;<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows Management Partner Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I saw THIS posting over on Mark Minasi&#8217;s forums that caught my eye.&nbsp; It gives you a random help file under the motto of: &#8220;A powershell help file a day, keeps Don Jones away&#8221;.&nbsp; \ud83d\ude42 Don responded pointing out one of our new V2 cmdlets:&nbsp; Get-Random.&nbsp; Since that cat is out of the bag and [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[180],"class_list":["post-6281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-get-random"],"acf":[],"blog_post_summary":"<p>I saw THIS posting over on Mark Minasi&#8217;s forums that caught my eye.&nbsp; It gives you a random help file under the motto of: &#8220;A powershell help file a day, keeps Don Jones away&#8221;.&nbsp; \ud83d\ude42 Don responded pointing out one of our new V2 cmdlets:&nbsp; Get-Random.&nbsp; Since that cat is out of the bag and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=6281"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6281\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=6281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=6281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=6281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}