none
Need a loop for the following script, if 1 then go back to top RRS feed

  • Question

  • [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
    $BB = [Microsoft.VisualBasic.Interaction]::InputBox("Please Enter Your BlackBox Computer Name", "Name", "$env:username")
    "Your BlackBox is $BB"
    $title = "Verify"
    $message = "$BB"

    $Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
     "Your site will be setup."

    $No = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
    "You can re-eneter your BlackBox."

    $options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No)

    $result = $host.ui.PromptForChoice($title, $message, $options, 0) 

    switch ($result)
    {
    0 {New-Item C:\test -type directory -Force
       New-Item C:\test\Test\1 -type directory -force }
     1 {goto} HOW DO GET THE NO WHEN CLICKED TO GO BACK TO THE TOP or to a certain point in the script
       }

    Duramaxster

    Thursday, April 24, 2014 9:42 PM

Answers

All replies

  • You can use a do or while loop.

    Start here:

    http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx

    Bill


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 24, 2014 9:51 PM
    Moderator
  • Thank you for the reply. In looking at you link it is way too much to sift through to find what I need. I do not know where to put the Do Statement. I will have a good 5 of these questions by the time I finish this script. Any change I could get more specific answer in placements?

    Thank you!
    Paul

     

    Duramaxster

    Thursday, April 24, 2014 10:07 PM
  • Maybe this example will give you an idea:

    add-type -AssemblyName System.Windows.Forms
    
    $red = $blue = $green = $null
    
    $Question1 = { 
        $script:red = [System.Windows.Forms.MessageBox]::Show("Do you like red?","Title", "YESNO", "question")
        $Question2.Invoke()
    }
    
    $Question2 = { 
        $script:blue = [System.Windows.Forms.MessageBox]::Show("Do you like blue?","Title", "YESNO", "question")
        $Question3.Invoke()
    }
    
    $Question3 = { 
        $script:green = [System.Windows.Forms.MessageBox]::Show("Do you like green?","Title", "YESNO", "question")
        $Question4.Invoke()
    }
    
    $Question4 = { 
        $Restart = [System.Windows.Forms.MessageBox]::Show("Would you like to start over?","Title", "YESNO", "question")
        If($Restart -match 'Yes'){$Question1.Invoke()}
    }
    
    $Question1.Invoke()
    
    $red
    $blue
    $green

    Thursday, April 24, 2014 10:57 PM
  • This might help, thank you sir, I will update you on the results.

    Thank you!
    Paul


    Duramaxster

    Thursday, April 24, 2014 11:06 PM
  • The trick here is that the script blocks invoke each other but the script will continue on the point of the first $Question1.Invoke().

    Thursday, April 24, 2014 11:15 PM
  • Simplest method to loop on a choice:

    $x=$true
    while($x){
        switch ($host.ui.PromptForChoice($title, $message, $options, 0) ){
              0 { Write-Host 'YES' -fore green} 
              1 {  Write-Host 'NO' -fore red;$x=$false} 
       } 
    }


    ¯\_(ツ)_/¯

    Friday, April 25, 2014 12:38 AM