Skip to content

Instantly share code, notes, and snippets.

@papinianus
Created December 28, 2022 11:56
Show Gist options
  • Save papinianus/22634ce952e5b9b1a8b34b165b45fc16 to your computer and use it in GitHub Desktop.
Save papinianus/22634ce952e5b9b1a8b34b165b45fc16 to your computer and use it in GitHub Desktop.
assign to pscustomobject
# PowerShell 7.3.1
$csv = "A,B`n1,2`n11,12`n21,22";
$file = "./test.csv";
if (Test-Path $file) {
Remove-Item $file;
}
Out-File -InputObject $csv -FilePath $file -NOClobber
$Object = [PSCustomObject]@{ A = 0; B = 0 }
Import-Csv $file | ForEach-Object { $Object.A += $_.A; $Object.B = $_.B }
Write-Host $Object
# @{A=33; B=22}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment