xlogI125’s blog

パソコン作業を効率化したい

PowerShell練習 @([AutomationNull]::Value)

メモ

空の$nullについてメモ

# PowerShell 5.1, Windows 11

Set-StrictMode -Version Latest

$emptyNull = [System.Management.Automation.Internal.AutomationNull]::Value

$null -eq $emptyNull             #=> True
@($emptyNull).Length             #=> 0
@(, $emptyNull).Length           #=> 1
@($emptyNull, $emptyNull).Length #=> 2

$null -eq $null        #=> True
@($null).Length        #=> 1
@(, $null).Length      #=> 1
@($null, $null).Length #=> 2

$null -eq (&{[void]123; return;      }) #=> True
@(&{[void]123; return;      }).Length   #=> 0

$null -eq (&{[void]123; return $null;}) #=> True
@(&{[void]123; return $null;}).Length   #=> 1