I am calling a PS function while passing it a string and a datatable variable. I want to extract all items in the datatable and store them in an object.
Here is my code from my script:
Function myFunc
{
param ($id, $dt)
$data = $dt | where-object ($_.ID -eq $ID)
}
$myVar = myFunc -id "stringID" -dt myDataTable
When this runs my data variable stays empty.
I have a breakpoint placed at the end of my project so I can try and play with the values. When I try and re-create the issue it works:
[DBG]: PS C:\WINDOWS\system32>> $abc = $myDataTable | where-object {$_.ID -eq $ID}
[DBG]: PS C:\WINDOWS\system32>> $abc
ID : //info here
Location : //info here
Managedr : //info here
It just will not work in my actual script.
$data. Also, is the lack of$in-dt myDataTablea typo in your question or in your actual script? And why do you have that parameter in the first place, if you're not using it?$data = $dt | where-object ($_.ID -eq $ID)