Tried both the cases to check if it is nullorempty but eventhough its null the statement is passing
$RequestorEmail=""
case1
if(($RequestorEmail -ne $null) -or ($RequestorEmail -ne ""))
case2
if ( -not [string]::IsNullOrEmpty( $RequestorEmail ) )
Tried both the cases to check if it is nullorempty but eventhough its null the statement is passing
$RequestorEmail=""
case1
if(($RequestorEmail -ne $null) -or ($RequestorEmail -ne ""))
case2
if ( -not [string]::IsNullOrEmpty( $RequestorEmail ) )
Hi @adityadugyala-0395 ,
maybe this helps:
$a = ""
if ($a) {
Write-Output "variable contains value"
}
else {
Write-Output "variable is empty"
}
Or vice versa:
$a = ""
if (!$a) {
Write-Output "variable is empty"
}
else {
Write-Output "variable contains value"
}
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten
In the situation you present, $RequestorEmail contains an empty string.
In your 1st test, since the variable $RequestorEmail is NOT $null (because it holds an empty string), and the string DOES contain an empty string, both conditions fail so the result is FALSE.
In your 2nd test, the variable $RequestorEmail IS empty and the IsNullOrEmpty is true, but you're negating that with the -not operator, so the result is FALSE.
What results where you expecting? And why?
15 people are following this question.