Summary: Use the default field in switch statement to have an assumed value.
I was playing with Select-String and would like to have it default to a value if none was trapped for. How can I do that?
Just use the Default keyword, and you can have an assumed value in the script block. In the following example, the switch is listening for the $DogSeesSquirrel object. If no values match, it returns ‘Squirrel runs free’.
switch ($dogseesquirrel)
{
'Back door' { $Response=’Bark!’}
'Couch' { $Response=’Growl a bit.’}
'Food bowl' { $Response=’Bark! Bark! Bark!’}
Default { $Response=’Squirrel runs free’ }
}
My apologies to our little dog for this example.