Disconnect-HPOVMgmt "breaks" if not connected


If I issue a "Disconnect-HPOVMgmt" when NOT connected it calls "break" go jump out of the cmdlet. Unfortunately, "break" is not a valid way to get out of a cmdlet, since it not only breaks the pipeline but it continues up the call stack until it finds a loop (for, foreach, do/while, switch, etc.) to break out of. If it can't find a loop it exits the script.

From the Windows PowerShell Language Specification Version 3.0 (http://www.microsoft.com/en-us/download/confirmation.aspx?id=36389)

8.5.1 The break statement
A break statement with a label-expression is referred to as a labeled break statement. A break statement without a label-expression is referred to as an unlabeled break statement.
Outside a trap statement, an unlabeled break statement directly within an iteration statement (§8.4) terminates execution of that smallest enclosing iteration statement. An unlabeled break statement directly within a switch statement (§8.6) terminates pattern matching for the current switch's switch-condition. See (§8.8) for details of using break from within a trap statement.
An iteration statement or a switch statement may optionally be preceded immediately by one statement label (§8.1.1).Such a statement label may be used as the target of a labeled break statement, in which case, that statement terminates execution of the targeted enclosing iteration statement.
A break need not be resolved in any local scope; the search for a matching label may continue up the calling stack even across script and function-call boundaries. If no matching label is found, the current command invocation is terminated.
The name of the label designated by label-expression need not have a constant value.
If label-expression is a unary-expression, it is converted to a string.
Closed Aug 17, 2016 at 4:48 PM by ChrisLynchHP


ChrisLynchHP wrote Aug 19, 2014 at 9:00 PM

This issue is fixed in the 1.10 Library, and will be fixed in the 1.06 library soon.