Script that spits our random command problem [Powershell]2019 Community Moderator ElectionEquivalent of *Nix 'which' command in PowerShell?How to recursively delete an entire directory with PowerShell 2.0?Powershell: Is it possible to set-alias on a piped command?Terminating a script in PowerShellHow to run a PowerShell scriptHow to handle command-line arguments in PowerShellPowerShell says “execution of scripts is disabled on this system.”What's the best way to determine the location of the current PowerShell script?How to pass an argument to a PowerShell script?Powershell script appears to execute command with wildcard

Use Mercury as quenching liquid for swords?

Book where society has been split into 2 with a wall down the middle where one side embraced high tech whereas other side were totally against tech

Ultrafilters as a double dual

Should we avoid writing fiction about historical events without extensive research?

Should I apply for my boss's promotion?

Why is there an extra space when I type "ls" on the Desktop?

Averaging over columns while ignoring zero entries

What exactly is the meaning of "fine wine"?

Short story about cities being connected by a conveyor belt

What is the purpose of a disclaimer like "this is not legal advice"?

Giving a talk in my old university, how prominently should I tell students my salary?

What is better: yes / no radio, or simple checkbox?

Inorganic chemistry handbook with reaction lists

How to install "rounded" brake pads

I am the light that shines in the dark

3.5% Interest Student Loan or use all of my savings on Tuition?

ESPP--any reason not to go all in?

Was this cameo in Captain Marvel computer generated?

Tool for measuring readability of English text

Professor forcing me to attend a conference, I can't afford even with 50% funding

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

Boss Telling direct supervisor I snitched

What would be the most expensive material to an intergalactic society?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?



Script that spits our random command problem [Powershell]



2019 Community Moderator ElectionEquivalent of *Nix 'which' command in PowerShell?How to recursively delete an entire directory with PowerShell 2.0?Powershell: Is it possible to set-alias on a piped command?Terminating a script in PowerShellHow to run a PowerShell scriptHow to handle command-line arguments in PowerShellPowerShell says “execution of scripts is disabled on this system.”What's the best way to determine the location of the current PowerShell script?How to pass an argument to a PowerShell script?Powershell script appears to execute command with wildcard










3















$k = get-command -all | measure | select-object count
$result = $k -replace "[@Count=]", ""
$rand = get-random -maximum $result
$minrand = $rand - 1
get-command -all -totalcount $rand | Select-Object -skip $minrand


This is supposed to spit out ONE command, alias, cmdlet whatever. I would hope that this would be useful for learning PowerShell.



The issue is that it spits out the same command over and over.










share|improve this question







New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Pipe Get-Random to Get-Command --> Get-Command | Get-Random

    – Vivek Kumar Singh
    2 days ago















3















$k = get-command -all | measure | select-object count
$result = $k -replace "[@Count=]", ""
$rand = get-random -maximum $result
$minrand = $rand - 1
get-command -all -totalcount $rand | Select-Object -skip $minrand


This is supposed to spit out ONE command, alias, cmdlet whatever. I would hope that this would be useful for learning PowerShell.



The issue is that it spits out the same command over and over.










share|improve this question







New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Pipe Get-Random to Get-Command --> Get-Command | Get-Random

    – Vivek Kumar Singh
    2 days ago













3












3








3








$k = get-command -all | measure | select-object count
$result = $k -replace "[@Count=]", ""
$rand = get-random -maximum $result
$minrand = $rand - 1
get-command -all -totalcount $rand | Select-Object -skip $minrand


This is supposed to spit out ONE command, alias, cmdlet whatever. I would hope that this would be useful for learning PowerShell.



The issue is that it spits out the same command over and over.










share|improve this question







New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












$k = get-command -all | measure | select-object count
$result = $k -replace "[@Count=]", ""
$rand = get-random -maximum $result
$minrand = $rand - 1
get-command -all -totalcount $rand | Select-Object -skip $minrand


This is supposed to spit out ONE command, alias, cmdlet whatever. I would hope that this would be useful for learning PowerShell.



The issue is that it spits out the same command over and over.







powershell command cmdlet






share|improve this question







New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Preben molandPreben moland

183




183




New contributor




Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Preben moland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    Pipe Get-Random to Get-Command --> Get-Command | Get-Random

    – Vivek Kumar Singh
    2 days ago












  • 1





    Pipe Get-Random to Get-Command --> Get-Command | Get-Random

    – Vivek Kumar Singh
    2 days ago







1




1





Pipe Get-Random to Get-Command --> Get-Command | Get-Random

– Vivek Kumar Singh
2 days ago





Pipe Get-Random to Get-Command --> Get-Command | Get-Random

– Vivek Kumar Singh
2 days ago












1 Answer
1






active

oldest

votes


















1














Your code is very complicated. You can just do this:



$Commands = Get-Command -All


Then keep running this:



Get-Random $Commands


To get a random different command each time.




Regarding your code, you don't ever need to do this (which would return a string result):



$k = get-command -all | measure | select-object count
$result = $k -replace "[@Count=]", ""


You should instead be doing something like this:



$k = get-command -all | measure | select-object count
$result = $k.count


Via which you're accessing the count property of $k and getting its integer value.



PowerShell returns objects with properties, so while you often see string based results in the console, when you want to manipulate those results you should work with the object properties. Piping an object to Get-Member is a good way to discover the properties of an object (as well as its methods etc.). For example try:



$k | Get-Member


To see its properties.



Get-Help, Get-Command and Get-Member are 3 of the most useful tools for discovering and learning PowerShell from within the shell.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Preben moland is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023541%2fscript-that-spits-our-random-command-problem-powershell%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Your code is very complicated. You can just do this:



    $Commands = Get-Command -All


    Then keep running this:



    Get-Random $Commands


    To get a random different command each time.




    Regarding your code, you don't ever need to do this (which would return a string result):



    $k = get-command -all | measure | select-object count
    $result = $k -replace "[@Count=]", ""


    You should instead be doing something like this:



    $k = get-command -all | measure | select-object count
    $result = $k.count


    Via which you're accessing the count property of $k and getting its integer value.



    PowerShell returns objects with properties, so while you often see string based results in the console, when you want to manipulate those results you should work with the object properties. Piping an object to Get-Member is a good way to discover the properties of an object (as well as its methods etc.). For example try:



    $k | Get-Member


    To see its properties.



    Get-Help, Get-Command and Get-Member are 3 of the most useful tools for discovering and learning PowerShell from within the shell.






    share|improve this answer





























      1














      Your code is very complicated. You can just do this:



      $Commands = Get-Command -All


      Then keep running this:



      Get-Random $Commands


      To get a random different command each time.




      Regarding your code, you don't ever need to do this (which would return a string result):



      $k = get-command -all | measure | select-object count
      $result = $k -replace "[@Count=]", ""


      You should instead be doing something like this:



      $k = get-command -all | measure | select-object count
      $result = $k.count


      Via which you're accessing the count property of $k and getting its integer value.



      PowerShell returns objects with properties, so while you often see string based results in the console, when you want to manipulate those results you should work with the object properties. Piping an object to Get-Member is a good way to discover the properties of an object (as well as its methods etc.). For example try:



      $k | Get-Member


      To see its properties.



      Get-Help, Get-Command and Get-Member are 3 of the most useful tools for discovering and learning PowerShell from within the shell.






      share|improve this answer



























        1












        1








        1







        Your code is very complicated. You can just do this:



        $Commands = Get-Command -All


        Then keep running this:



        Get-Random $Commands


        To get a random different command each time.




        Regarding your code, you don't ever need to do this (which would return a string result):



        $k = get-command -all | measure | select-object count
        $result = $k -replace "[@Count=]", ""


        You should instead be doing something like this:



        $k = get-command -all | measure | select-object count
        $result = $k.count


        Via which you're accessing the count property of $k and getting its integer value.



        PowerShell returns objects with properties, so while you often see string based results in the console, when you want to manipulate those results you should work with the object properties. Piping an object to Get-Member is a good way to discover the properties of an object (as well as its methods etc.). For example try:



        $k | Get-Member


        To see its properties.



        Get-Help, Get-Command and Get-Member are 3 of the most useful tools for discovering and learning PowerShell from within the shell.






        share|improve this answer















        Your code is very complicated. You can just do this:



        $Commands = Get-Command -All


        Then keep running this:



        Get-Random $Commands


        To get a random different command each time.




        Regarding your code, you don't ever need to do this (which would return a string result):



        $k = get-command -all | measure | select-object count
        $result = $k -replace "[@Count=]", ""


        You should instead be doing something like this:



        $k = get-command -all | measure | select-object count
        $result = $k.count


        Via which you're accessing the count property of $k and getting its integer value.



        PowerShell returns objects with properties, so while you often see string based results in the console, when you want to manipulate those results you should work with the object properties. Piping an object to Get-Member is a good way to discover the properties of an object (as well as its methods etc.). For example try:



        $k | Get-Member


        To see its properties.



        Get-Help, Get-Command and Get-Member are 3 of the most useful tools for discovering and learning PowerShell from within the shell.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        Mark WraggMark Wragg

        14.5k42145




        14.5k42145






















            Preben moland is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            Preben moland is a new contributor. Be nice, and check out our Code of Conduct.












            Preben moland is a new contributor. Be nice, and check out our Code of Conduct.











            Preben moland is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023541%2fscript-that-spits-our-random-command-problem-powershell%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved