Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 612 Bytes

File metadata and controls

29 lines (21 loc) · 612 Bytes

In PowerShell, if you convert null to string, it will become an empty string.

$ ([string]($null)).GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

If you output it:

$ ([string]($null))

$ ($null)
$

If you get the count:

$ ($null).Count
0
$ ([string]($null)).Count
1 # Now it has a count after you converting that `null` to `string`.

What a strange behavior of PowerShell! 😲