Hash tables have their uses, but Powershell most uses PSObject, which from a basic standpoint is an array of hashtables. Take a look at these basic examples:
#Manual
$props = @{
FirstName = 'Alice'
LastName = 'Smith'
}
New-Object -TypeName PSObject -Property $props
#Accelerator
[PSCustomObject]@{
FirstName = 'Alice'
LastName = 'Smith'
}
When anything is imported, it is typically generating a PSObject, such as Import-CSV. Without seeing the function it’s hard to assist, but the name of params (while I’m sure it’s just an example) is more of a type than a proper param name. If you look at this, you can see how an imported CSV is processed by the function:
function Get-MyBalanceFunction {
[CmdletBinding()]
param (
[Parameter(
Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
[string]$Account,
[Parameter(
Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
[string]$AccountNumber,
[Parameter(
Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
[float]$Amount
)
begin {}
process {
Write-Verbose ('Processing account {0} ({1}) with amount {2}' -f $Account, $AccountNumber, $Amount)
}
end {}
}
$csv = @"
Account, AccountNumber, Amount
Smith Farms,42241344,10023.23
Johnson Farms,63424242,-23320.44
AgriFam,23434345,14436.58
"@ | ConvertFrom-CSV
foreach ($acct in $csv) {
Get-MyBalanceFunction -Account $acct.Account -AccountNumber $acct.AccountNumber -Amount $acct.Amount -Verbose
}
But you can even use the pipeline rather than the loop, as simple as this:
$csv | Get-MyBalanceFunction -Verbose
Both produce the same output:
VERBOSE: Processing account Smith Farms (42241344) with amount 10023.23
VERBOSE: Processing account Johnson Farms (63424242) with amount -23320.44
VERBOSE: Processing account AgriFam (23434345) with amount 14436.58
However, when I see ‘balance’, you can also do something like this:
PS C:\Users\rasim> $csv | Measure-Object -Property Amount -Sum -Average
Count : 3
Average : 379.79
Sum : 1139.37
Maximum :
Minimum :
StandardDeviation :
Property : Amount