$data = (Get-Content C:\newData.txt) | Sort-Object -Descending foreach ($line in $data) { $lineItems = $line.Split("{;}") foreach ($item in $lineItems) { $item = $item.Trim() } $relCode = $lineItems[0] $acct = $list.Items | where {$_['Rel Code'] -eq $relCode} if ( $acct -eq $null) { Write-host "acct is null" } else { $acct["Account_x0020_data"] = $acctTable $acct.Update(); }
Above powershell code is always returning a null item. Where as if I hard code the line
$acct = $list.Items | where {$_['Rel Code'] -eq 170}
instead of
$acct = $list.Items | where {$_['Rel Code'] -eq $relCode}
Then the code runs fine. Else every time it returns null item. I tried printing $relCode value it is up to the mark. Any help please.