IF ELSE re exists: csv values

I have a csv input to a PowerShell script that has two email fields; the one that will always contain the value and the value that will sometimes be, and when the last value exists, the one I want to use to set the value used to set the mailcontact field later in the script to a variable $WriteEmail

,

So, I have the following to read the CSV:

# Read contacts
ForEach ($contact in $contactfile) {

# Read attributes
$sourceEmail=$contact.Email
$sourceOutlookEmail=$contact.OutlookEmail

      

And I basically need this:

IF $sourceOutlookEmail IsNullOrWhitespace
THEN $WriteEmail=$sourceEmail
ELSE $WriteEmail=$sourceOutlookEmail

      

I just can't get the syntax right, I've tried all sorts of things. I know this is relatively simple, I just cannot get it to work.

+3


source to share


1 answer


You can use the static .net method IsNullOrWhiteSpace

:



if ([string]::IsNullOrWhiteSpace($sourceOutlookEmail))
{
   $WriteEmail=$sourceEmail
}
else
{
   $WriteEmail=$sourceOutlookEmail
}

      

+4


source







All Articles