View Single Post
Old 08-26-2008   #3 (permalink)
Shay Levy [MVP]


 
 

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 SpecsSystem Spec