<t>Powershell 7+<br/>
<br/>
Powershell 7 introduces native null coalescing, null conditional assignment, and ternary operators in Powershell.<br/>
<br/>
Null Coalescing<br/>
<br/>
$null ?? 100 # Result is 100<br/>
<br/>
"Evaluated" ?? (Expensive-Operation "Not Evaluated") # Right side here is not evaluated<br/>
<br/>
```<br/>
<br/>
**Null Conditional Assignment**<br/>
<br/>
```<br/>
$x = $null<br/>
$x ??= 100 # $x is now 100<br/>
$x ??= 200 # $x remains 100<br/>
<br/>
```<br/>
<br/>
**Ternary Operator**<br/>
<br/>
```<br/>
$true ? "this value returned" : "this expression not evaluated"<br/>
$false ? "this expression not evaluated" : "this value returned"<br/>
<br/>
```<br/>
<br/>
Previous Versions:<br/>
<br/>
No need for the Powershell Community Extensions, you can use the standard Powershell if statements as an expression:<br/>
<br/>
```<br/>
variable = if (condition) { expr1 } else { expr2 }<br/>
<br/>
```<br/>
<br/>
So to the replacements for your first C# expression of:<br/>
<br/>
```<br/>
var s = myval ?? "new value";<br/>
<br/>
```<br/>
<br/>
becomes one of the following (depending on preference):<br/>
<br/>
```<br/>
$s = if ($myval -eq $null) { "new value" } else { $myval }<br/>
$s = if ($myval -ne $null) { $myval } else { "new value" }<br/>
<br/>
```<br/>
<br/>
or depending on what $myval might contain you could use:<br/>
<br/>
```<br/>
$s = if ($myval) { $myval } else { "new value" }<br/>
<br/>
```<br/>
<br/>
and the second C# expression maps in a similar way:<br/>
<br/>
```<br/>
var x = myval == null ? "" : otherval;<br/>
<br/>
```<br/>
<br/>
becomes<br/>
<br/>
```<br/>
$x = if ($myval -eq $null) { "" } else { $otherval }<br/>
<br/>
```<br/>
<br/>
Now to be fair, these aren't very snappy, and nowhere near as comfortable to use as the C# forms.<br/>
<br/>
You might also consider wrapping it in a very simple function to make things more readable:<br/>
<br/>
```<br/>
function Coalesce($a, $b) { if ($a -ne $null) { $a } else { $b } }<br/>
<br/>
$s = Coalesce $myval "new value"<br/>
<br/>
```<br/>
<br/>
or possibly as, IfNull:<br/>
<br/>
```<br/>
function IfNull($a, $b, $c) { if ($a -eq $null) { $b } else { $c } }<br/>
<br/>
$s = IfNull $myval "new value" $myval<br/>
$x = IfNull $myval "" $otherval<br/>
<br/>
```<br/>
<br/>
As you can see a very<br/>
<br/>
*(Réponse tronquée)*</t>