Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is what we provide in the <a href="http://pscx.codeplex.com" rel="noreferrer">PowerShell Community Extensions</a>:</p> <pre><code>&lt;# .SYNOPSIS Similar to the C# ?? operator e.g. name = value ?? String.Empty .DESCRIPTION Similar to the C# ?? operator e.g. name = value ?? String.Empty; where value would be a Nullable&amp;lt;T&amp;gt; in C#. Even though PowerShell doesn't support nullables yet we can approximate this behavior. In the example below, $LogDir will be assigned the value of $env:LogDir if it exists and it's not null, otherwise it get's assigned the result of the second script block (C:\Windows\System32\LogFiles). This behavior is also analogous to Korn shell assignments of this form: LogDir = ${$LogDir:-$WinDir/System32/LogFiles} .PARAMETER PrimaryExpr The condition that determines whether the TrueBlock scriptblock is used or the FalseBlock is used. .PARAMETER AlternateExpr This block gets evaluated and its contents are returned from the function if the Conditon scriptblock evaluates to $true. .EXAMPLE C:\PS&gt; $LogDir = ?? {$env:LogDir} {"$env:windir\System32\LogFiles"} $LogDir is set to the value of $env:LogDir unless it doesn't exist, in which case it will then default to "$env:windir\System32\LogFiles". #&gt; filter Invoke-NullCoalescing { param([scriptblock]$PrimaryExpr = $(throw "Parameter '-primaryExpr' (position 1) required"), [scriptblock]$AlternateExpr = $(throw "Parameter '-alternateExpr' (position 2) required")) if ($primaryExpr -ne $null) { $result = &amp;$primaryExpr if ($result -ne $null -and "$result" -ne '') { $result } else { &amp;$alternateExpr } } else { &amp;$alternateExpr } } New-Alias ?? Invoke-NullCoalescing PS&gt; ?? {$xyzzy} {"empty"} empty PS&gt; ?? {$psversiontable} {"empty"} Name Value ---- ----- CLRVersion 2.0.50727.4927 BuildVersion 6.1.7600.16385 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload