Name Balance
---- -------
Tom (0.09)
Dick 600.5
Harry (0.13)
Sally 5.25
When I import the CSV (see above data) using Import-Csv, the "Balance" column imports as a string and I can't do any math on it. Note: The ( ) surrounded values are negatives.
HELP!
$csv = Import-Csv -Path $file | select -Property 'Name','Balance'
$csv | Get-Member
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Balance NoteProperty string Balance=(0.09)
Name NoteProperty string Name=Tom
$csv.ForEach({ $_.Balance = $_.Balance -replace '\(([\d.]+)\)', '-$1' -as [double] })then the values would be actual doubles you can do math on($csv.balance -replace "\(|\)","" | Measure-Object -Sum).Sum.-asin the same line was removing some of the values, I did it seperately after simplifying the-replacewith just$csv.ForEach({ $_.Balance = $_.Balance -replace '\(', '-' -replace'\)','' })seemed to do the trick. The script came out great. Thanks again all!