Be careful while invoking multiple functions in powershell.
PS > function retTrue () { return $true }
PS > function retFalse () { return $false }
PS > retTrue
True
PS > retFalse
False
PS > retTrue -and retFalse
True
PS > (retTrue) -and (retFalse)
False
Tuesday, May 11, 2010
PowerShell "Magic" Weirdness [Arrays]
PS > function f(){ return @() }
PS > $a=f
PS > $a -eq $null
True
PS > $a.length
PS > $a = @(f)
PS > $a
PS > $a.length
0
PS > $a -eq $null
PS > $a -ne $null
PS > ($a -ne $null).length
0
PS > $null -eq $a
False
PS > $null -ne $a
True
Here $a is an array with no elements, empty set, but not null.
PS > $a=f
PS > $a -eq $null
True
PS > $a.length
PS > $a = @(f)
PS > $a
PS > $a.length
0
PS > $a -eq $null
PS > $a -ne $null
PS > ($a -ne $null).length
0
PS > $null -eq $a
False
PS > $null -ne $a
True
Here $a is an array with no elements, empty set, but not null.
Subscribe to:
Posts (Atom)
-
Objects are complex data type Const myObj = {}; console.log(myObj); const person = { firstName : ‘S’, lastName: ‘Man’, Age: 4 } person...
-
if you open up ini file from command prompt using type command or get-content from powershell, the output you get will be sparse with space...
-
$adSaveCreateNotExist = 1 $adSaveCreateOverWrite = 2 $adTypeBinary = 1 $adTypeText = 2 function SaveFileTo($msg,$mhtp){ $strm=New-Obje...