![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Case/Select functionality I'm writing a script to check if a VPN connection has failed. I want to display the return code from a failed ping. Is there any way to do a Case, Select? Right now I just have a bunch of If statements: if ($a -eq 11001) { $errorcode = "Buffer Too Small "} if ($a -eq 11002) { $errorcode = "Destination Net Unreachable "} if ($a -eq 11003) .... Any ideas? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Case/Select functionality "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message news:97570D07-EE48-4C57-9A30-378CD3A29EE9@microsoft.com... > I'm writing a script to check if a VPN connection has failed. I want to > display the return code from a failed ping. Is there any way to do a > Case, > Select? Right now I just have a bunch of If statements: > > if ($a -eq 11001) > { $errorcode = "Buffer Too Small "} > if ($a -eq 11002) > { $errorcode = "Destination Net Unreachable "} > if ($a -eq 11003) > ... switch $a { 11001 { $errorcode = 'Buffer too small' } 11002 { $errorcode = 'Destination net unreachable; } ... default { $errorcode = 'Unknown error code' } } -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Case/Select functionality I knew that would be simple. Thanks for helping out a newbie on his second day using Pshell. "Keith Hill" wrote: > "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message > news:97570D07-EE48-4C57-9A30-378CD3A29EE9@microsoft.com... > > I'm writing a script to check if a VPN connection has failed. I want to > > display the return code from a failed ping. Is there any way to do a > > Case, > > Select? Right now I just have a bunch of If statements: > > > > if ($a -eq 11001) > > { $errorcode = "Buffer Too Small "} > > if ($a -eq 11002) > > { $errorcode = "Destination Net Unreachable "} > > if ($a -eq 11003) > > ... > > switch $a { > 11001 { $errorcode = 'Buffer too small' } > 11002 { $errorcode = 'Destination net unreachable; } > ... > default { $errorcode = 'Unknown error code' } > } > > -- > Keith > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Case/Select functionality "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message news:F971A17A-7FCA-46EA-95AD-2703CFE8C9EC@microsoft.com... >I knew that would be simple. Thanks for helping out a newbie on his second > day using Pshell. No problem. Hang in there. The learning curve can be a bit steep but you have a couple of things going for you. First this forum is pretty responsive even to newbie questions and second the payoff is well worth the potential up front frustration. -- Keith |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Case/Select functionality I tried what you said and I keep getting an error : Missing '{' in switch statement. At C:\Documents and Settings\jeff\test2.ps1:12 char:9 + switch $ <<<< b { What am I missing? Here is a snippet, (the names have been changed): function init () { $GLOBAL ingtarget = "www.gohome.com"$GLOBAL:LocalRouter = "172.16.1.1" $GLOBAL:externaltarget = "www.google.com" } function pingit { $global:targetresponse = Get-WmiObject -Class Win32_PingStatus -Filter "Address= '$global ingtarget'"$a = $global:targetresponse.statuscode switch $a { 11001 { $global:targeterror = 'Buffer too small' } 11002 { $global:targeterror = 'Destination net unreachable' } 11003 { $global:targeterror = "Destination Host Unreachable "} 11004 { $global:targeterror = "Destination Protocol Unreachable"} 11005 { $global:targeterror = "Destination Port Unreachable "} 11006 { $global:targeterror = "No Resources "} 11007 { $global:targeterror = "Bad Option "} 11008 { $global:targeterror = "Hardware Error "} 11009 { $global:targeterror = "Packet Too Big "} 11010 { $global:targeterror = "Request Timed Out" } 11011 { $global:targeterror = "Bad Request "} 11012 { $global:targeterror = "Bad Route "} 11013 { $global:targeterror = "TimeToLive Expired Transit "} 11014 { $global:targeterror = "TimeToLive Expired Reassembly" } 11015 { $global:targeterror = "Parameter Problem "} 11016 { $global:targeterror = "Source Quench "} 11017 { $global:targeterror = "Option Too Big "} 11018 { $global:targeterror = "Bad Destination "} 11032 { $global:targeterror = "Negotiating IPSEC" } 11050 { $global:targeterror = "General Failure "} default { $global:targeterror = 'Unknown error code' } } } "Keith Hill" wrote: > "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message > news:F971A17A-7FCA-46EA-95AD-2703CFE8C9EC@microsoft.com... > >I knew that would be simple. Thanks for helping out a newbie on his second > > day using Pshell. > > No problem. Hang in there. The learning curve can be a bit steep but you > have a couple of things going for you. First this forum is pretty > responsive even to newbie questions and second the payoff is well worth the > potential up front frustration. > > -- > Keith > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Case/Select functionality NEVER MIND... switch ($a) Forgot the parens... "LoneWolf" wrote: > I tried what you said and I keep getting an error : > > Missing '{' in switch statement. > At C:\Documents and Settings\jeff\test2.ps1:12 char:9 > + switch $ <<<< b { > > What am I missing? Here is a snippet, (the names have been changed): > > function init () > { > $GLOBAL ingtarget = "www.gohome.com"> $GLOBAL:LocalRouter = "172.16.1.1" > $GLOBAL:externaltarget = "www.google.com" > } > > function pingit > { > $global:targetresponse = Get-WmiObject -Class Win32_PingStatus -Filter > "Address= '$global ingtarget'"> $a = $global:targetresponse.statuscode > switch $a { > 11001 { $global:targeterror = 'Buffer too small' } > 11002 { $global:targeterror = 'Destination net unreachable' } > 11003 { $global:targeterror = "Destination Host Unreachable "} > 11004 { $global:targeterror = "Destination Protocol Unreachable"} > 11005 { $global:targeterror = "Destination Port Unreachable "} > 11006 { $global:targeterror = "No Resources "} > 11007 { $global:targeterror = "Bad Option "} > 11008 { $global:targeterror = "Hardware Error "} > 11009 { $global:targeterror = "Packet Too Big "} > 11010 { $global:targeterror = "Request Timed Out" } > 11011 { $global:targeterror = "Bad Request "} > 11012 { $global:targeterror = "Bad Route "} > 11013 { $global:targeterror = "TimeToLive Expired Transit "} > 11014 { $global:targeterror = "TimeToLive Expired Reassembly" } > 11015 { $global:targeterror = "Parameter Problem "} > 11016 { $global:targeterror = "Source Quench "} > 11017 { $global:targeterror = "Option Too Big "} > 11018 { $global:targeterror = "Bad Destination "} > 11032 { $global:targeterror = "Negotiating IPSEC" } > 11050 { $global:targeterror = "General Failure "} > default { $global:targeterror = 'Unknown error code' } > } > > } > > > "Keith Hill" wrote: > > > "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message > > news:F971A17A-7FCA-46EA-95AD-2703CFE8C9EC@microsoft.com... > > >I knew that would be simple. Thanks for helping out a newbie on his second > > > day using Pshell. > > > > No problem. Hang in there. The learning curve can be a bit steep but you > > have a couple of things going for you. First this forum is pretty > > responsive even to newbie questions and second the payoff is well worth the > > potential up front frustration. > > > > -- > > Keith > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Case/Select functionality "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message news:CF471119-7B9D-4A98-B051-B34B9D59952A@microsoft.com... > NEVER MIND... > Oops. Sorry about that. -- Keith |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Case/Select functionality No problem. Hard-won knowlege is the best knowlege. "Keith Hill" wrote: > "LoneWolf" <LoneWolf@discussions.microsoft.com> wrote in message > news:CF471119-7B9D-4A98-B051-B34B9D59952A@microsoft.com... > > NEVER MIND... > > > > Oops. Sorry about that. > > -- > Keith > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script that uses the DatePart & Case select | VB Script | |||
| select case does not work ... why? | VB Script | |||
| Logon script - function array and select case not working | VB Script | |||
| Re: Select case question | VB Script | |||
| Select Files - Disable or Enable Full Row Select | Tutorials | |||