I have a csv input to a PowerShell script that has two email fields; one that will always contain a value and one that sometimes will, and when the latter value exists, that's the one I want to use to set a value used to set a mailcontact field later in the script, for the variable $WriteEmail.
So I've got the following to read the CSV:
# Read contacts
ForEach ($contact in $contactfile) {
# Read attributes
$sourceEmail=$contact.Email
$sourceOutlookEmail=$contact.OutlookEmail
And I need it to basically do:
IF $sourceOutlookEmail IsNullOrWhitespace
THEN $WriteEmail=$sourceEmail
ELSE $WriteEmail=$sourceOutlookEmail
I just can't get the syntax correct, I've tried all kinds of stuff. I know it's relatively simple, I just can't get it to work.
You can use the static .net IsNullOrWhiteSpace method:
if ([string]::IsNullOrWhiteSpace($sourceOutlookEmail))
{
$WriteEmail=$sourceEmail
}
else
{
$WriteEmail=$sourceOutlookEmail
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With