user7376830
user7376830

Reputation: 3

Find Empty Value in Column

Pardon me if this question has already been answered on this site. I haven't been able to find it through my research thus far.

Question: As I step through each row of formatted table , I'm trying to determine if a column (CompletionDate) is missing it's value

Below is an example table:

DueDate, StartDate, CompletionDate         
2017-06-10T22:00:29.08, 2017-05-30T20:38:37.913, 2017-05-30T20:44:05.517
2017-06-09T16:00:21.38, 2017-06-07T15:55:14.627,

Below is some of my code thus far:

foreach ($row in $tableData) {
    if ($row.CompletionDate -eq ''){
        write-host 'no value'
    }
    else {
        Write-Host 'has value'
    }
}

Thanks in advance for your help. If this question has been answered before, please just let me know where it is, and I'll take this question down. }

Upvotes: 0

Views: 76

Answers (2)

Esperento57
Esperento57

Reputation: 17472

try this

foreach ($row in $tableData) 
{
    if ($row.CompletionDate)
    {
      'has value'
    }
    else 
    {
      'no value'
    }
}

Upvotes: 1

k7s5a
k7s5a

Reputation: 1377

You can use the IsNullOrEmpty method:

foreach ($row in $tableData) {
    if ([string]::IsNullOrEmpty($row.CompletionDate)){
        write-host 'no value'
    }
    else {
        Write-Host 'has value'
    }
}

Upvotes: 2

Related Questions