I"m somewhat new to PowerShell and I'm trying to do something that is pretty easy in other languages like C#.NET and Java.
What I'm doing:
- I'm trying to read in a CSV file with 3 defined columns of "clientid", "parentid" and "schoolid".
- I need to group to just unique rows of the data.
I need to access these rows of data to parse and perform other functions with the data by passing as parameters
$obj = Import-Csv $Name | Group-Object clientid, parentid, schoolid | foreach-object { $_.group | sort-object clientid, parentid, schoolid | select clientid, parentid, schoolid -last 1 } foreach ( $row in $obj ) { $_clientid = $row[0]; $_parentid = $row[1]; $_schoolid = $row[2]; Other-Function -client $_.clientid -parent $_.parentid -schoolid $_.schoolid }
foreachloop,$rowwill be the current object. You can directly access its properties like$row.clientid, which can then be used As a parameter value in your function.[n]is used to access the nth item (starting from 0) in that position of a collection.$objis a collection of objects with each of them having all of the properties you selected. So$obj[0]would return the first of those objects with all of its properties. The foreach loop just allows you to iterate over that collection. So$row[1]would almost always return nothing unless $obj contained a collection of collections.