Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Powershell script returns the exception "Cannot index into a null array"

$
0
0
$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.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>