I am trying to pass an Item to a SPE Function as follows:
function ImportTask ($importTask, $taskItem) {
$taskName = $taskItem.Name
$importTask.ItemTitle = $taskItem.Fields["Item Title"].Value
}
$taskObj = New-Object MyNamespace.Task
$contextItem = Get-Item -Path "."
ImportTask($taskObj, $contextItem)
However, when executed, I get the following error:
Cannot index into a null array.
At line:5 char:2
+ $importTask.ItemTitle = $taskItem.Fields["Item Title"].Value
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Any suggestions why I cannot retrieve the value?