I’m trying to check to see if a variable is 0 or maybe blank… and react accordingly. Here is my following code:


```
If($ClientFSA -eq 0 -and $ClientFSA -like ''){
$FSA = @{
"LME" = "HC2";
"ME" = "FSA";
"FSA"="FSA";
"DC" = "DCA";
"DCA" = "DCA";
"PKG" = "PK";
"TRN" = "TRN";
"AVIDIA" = "ABH";
"UMB" = "UMB"
}
}Else{$FSA = @{$ClientLME = "HC2"; $ClientFSA = "FSA"; $ClientDCA = "DCA"}}

$FSAImport = Import-Csv $File
ForEach($row in $FSAImport){
$row.FSA_DCA = $FSA[$row.FSA_DCA]
}
```

$clientFSA is populated from an access query earlier in the script. My problem is when the access cells in question are blank I get the error that:

Cannot index into a null array.
$row.FSA_DCA = $FSA[$row.FSA_DCA]
3 Spice ups

Have you tried checking if the value is null?

If($ClientFSA -eq $Null)
1 Spice up

Why not make use of the type casting and use:

if ( -NOT $ClientFSA)

Instead?

2 Spice ups
If(!$ClientFSA) {
2 Spice ups

wow… I know I overlook simple solutions… but this one is leader in the clubhouse so far.

All three of your answers are correct, just slightly different syntax essentially.

This is another one of those things that you’ll learn to look for, always assume that your value can be $null, which you’d think would be like 0, but its not. Always check for $null :slight_smile:

That’s silly, because if it is null it is false.

So as ther others said,

if($variable){  # any value really, this is true
    # do stuff
}

But it will be false for $null, $false etc.