locked
Get-Random with Variables and Messagebox RRS feed

  • Question

  • Hello scripting guys,

      I am trying to assist out HR team with a project that  brings up a message box with a ramdomly selected message. I am using get-random, however when I run my script it pulls up all of the messages and not just one random one. I have looked online and I cant find anything like what I am doing. Here is the script.

    $A = [System.Windows.Forms.MessageBox]::Show("test 1")
    $B = [System.Windows.Forms.MessageBox]::Show("Test 2")
    $C = [System.Windows.Forms.MessageBox]::Show("Test 3")
    $D = [System.Windows.Forms.MessageBox]::Show("Test 4")
    $E = [System.Windows.Forms.MessageBox]::Show("Test 5")
    $F = [System.Windows.Forms.MessageBox]::Show("Test 6")
    $G = [System.Windows.Forms.MessageBox]::Show("Test 7")
    $H = [System.Windows.Forms.MessageBox]::Show("Test 8")
    $I = [System.Windows.Forms.MessageBox]::Show("Test 9")
    $J = [System.Windows.Forms.MessageBox]::Show("Test 10")
    
    $A,$B,$C,$D,$E,$F,$G,$H,$I,$J | Get-Random

    Any thoughts?

    Richard

    Friday, September 23, 2016 11:54 AM

Answers

  • Hi Richard,

    the moment you call the .NET Method, the box is shown. Randomly select the text instead:

    "test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6", "Test 7", "Test 8", "Test 9", "Test 10" | Get-Random | %{ [System.Windows.Forms.MessageBox]::Show($_) }

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Richardlaw Friday, September 23, 2016 12:05 PM
    Friday, September 23, 2016 12:00 PM

All replies

  • Hi Richard,

    the moment you call the .NET Method, the box is shown. Randomly select the text instead:

    "test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6", "Test 7", "Test 8", "Test 9", "Test 10" | Get-Random | %{ [System.Windows.Forms.MessageBox]::Show($_) }

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Richardlaw Friday, September 23, 2016 12:05 PM
    Friday, September 23, 2016 12:00 PM
  • Perfect it worked Thanks.
    Friday, September 23, 2016 12:05 PM