![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Break is not working ? $title = "Defrag Drive" $message = "Select Drive letter to perform defragamention." $cdrive = New-Object System.Management.Automation.Host.ChoiceDescription "&C drive", "Analyse C:\ drive." $ddrive = New-Object System.Management.Automation.Host.ChoiceDescription "&D drive", "Analyse D:\ drive." $quit = New-Object System.Management.Automation.Host.ChoiceDescription "&Quit", "Quit this session." $options = [System.Management.Automation.Host.ChoiceDescription[]]($cdrive, $ddrive,$quit) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 {$cmdline = "cmd /c c:\windows\system32\defrag.exe c:\ -a > c:\%computername%_defrag.txt"} 1 {$cmdline = "cmd /c c:\windows\system32\defrag.exe d:\ -a > d:\%computername%_defrag.txt"} 2 {break} } $result ===================== I select Q, and it suppose to quit session, but it did not ? Why ? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Break is not working ? Quit meaning i wld like to quit the program. I wld like to make the choice via the switch statement, if select q, which is equal to 2, after break, the program did not quit. I find it very strange. It did not work at my side. Even i put break in every switch statement, it still does not break. |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Break is not working ? Hello IT, It is working for me. What do you mean by 'quit session'? Also, consider adding 'break; to each of the other switch items (unless you want all items to be processed): switch ($result){ 0 {$cmdline = "cmd /c c:\windows\system32\defrag.exe c:\ -a > c:\%computername%_defrag.txt"; break} 1 {$cmdline = "cmd /c c:\windows\system32\defrag.exe d:\ -a > d:\%computername%_defrag.txt"; break} 2 {break} } --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic IS> $title = "Defrag Drive" IS> $message = "Select Drive letter to perform defragamention." IS> $cdrive = New-Object IS> System.Management.Automation.Host.ChoiceDescription IS> "&C drive", "Analyse C:\ drive." IS> $ddrive = New-Object IS> System.Management.Automation.Host.ChoiceDescription IS> "&D drive", "Analyse D:\ drive." IS> $quit = New-Object IS> System.Management.Automation.Host.ChoiceDescription IS> "&Quit", "Quit this session." IS> $options = IS> [System.Management.Automation.Host.ChoiceDescription[]]($cdrive, IS> $ddrive,$quit) IS> $result = $host.ui.PromptForChoice($title, $message, $options, 0) IS> switch ($result) IS> { IS> 0 {$cmdline = "cmd /c c:\windows\system32\defrag.exe c:\ -a IS> > IS> c:\%computername%_defrag.txt"} IS> 1 {$cmdline = "cmd /c c:\windows\system32\defrag.exe d:\ -a IS> > IS> d:\%computername%_defrag.txt"} IS> 2 {break} IS> } IS> $result IS> ===================== IS> I select Q, and it suppose to quit session, but it did not ? Why ? |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Break is not working ? u are right man. "Shay Levy [MVP]" <no@xxxxxx> wrote in message news:89228ed2406d88cad58f1e6a0c7d@xxxxxx Quote: > Hello IT, > > If you mean quit = close powershell then replace 'break' with 'exit' > > ... > 2 {exit} > > > --- > Shay Levy > Windows PowerShell MVP > http://blogs.microsoft.co.il/blogs/ScriptFanatic > > IS> Quit meaning i wld like to quit the program. > IS> IS> I wld like to make the choice via the switch statement, if select > q, > IS> which is equal to 2, after break, the program did not quit. > IS> IS> I find it very strange. It did not work at my side. Even i put > break > IS> in every switch statement, it still does not break. > IS> > > |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Break is not working ? Hello IT, If you mean quit = close powershell then replace 'break' with 'exit' .... 2 {exit} --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic IS> Quit meaning i wld like to quit the program. IS> IS> I wld like to make the choice via the switch statement, if select q, IS> which is equal to 2, after break, the program did not quit. IS> IS> I find it very strange. It did not work at my side. Even i put break IS> in every switch statement, it still does not break. IS> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: How Many Laws did I break? | Vista General | |||
| How to break an old raid | Drivers | |||
| Did I break it ? | General Discussion | |||
| Break away | Vista General | |||