Created
December 28, 2022 11:56
-
-
Save papinianus/22634ce952e5b9b1a8b34b165b45fc16 to your computer and use it in GitHub Desktop.
assign to pscustomobject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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