Consider such function:
$missed = "{716C1AD7-0DA6-45e6-854E-4B466508EB96}"
function Test($foo = $missed, $bar = $missed)
{
if(!$foo)
{
throw "error"
}
if(!$bar)
{
throw "error"
}
}
I whould like to call this function this way
Test -foo $foo -bar $bar
But if $foo or $bar is $null, exception will be thrown. The naive solution is
if($foo -and $bar)
{
Test -foo $foo -bar $bar
}
elseif ($foo)
{
Test -foo $foo
}
elseif ($bar)
{
Test -bar $bar
}
else
{
Test
}
How can I rewrite this if/else block in one/two lines?