LucD,
you meant like this ?
$code = @'
"### Output ###"
"" | Select @{n='OS_Sockets';e={(gwmi Win32_Processor | measure -Property NumberOfCores).count}} | Select CSName,'OS_Sockets' | ConvertTo-Csv -UseCulture -NoTypeInformation
"### Output ###"
"" | Select @{n='OS_Cores';e={(gwmi Win32_Processor | measure -Property NumberOfLogicalProcessors).count}} | Select CSName,'OS_Cores' | ConvertTo-Csv -UseCulture -NoTypeInformation
"### Output ###"
"" | Select @{n='OS_Total_vCPU';e={ (gwmi Win32_Processor | measure -Property NumberOfLogicalProcessors -sum).sum}}| Select CSName,'OS_Total_vCPU' | ConvertTo-Csv -UseCulture -NoTypeInformation
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke
$dummy, $out1, $out2, $out3 = $result.ScriptOutput -split '### Output ###'
$out1 = $out1.TrimStart("`n`r") -split "`n`r"
$out2 = $out2.TrimStart("`n`r")
$out3 = $out3.TrimStart("`n`r")
$report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS_Sockets' -Value ([int]$out1) -PassThru | Add-Member -MemberType NoteProperty -Name 'OS_Cores' -Value ([int]$out2) -PassThru |
Add-Member -MemberType NoteProperty -Name 'OS_Total_vCPU' -Value ([int]$out3) -PassThru
}
$report1 | ft -auto
$report1 | Export-Csv -Force -Path $reportlocation1 -UseCulture -NoTypeInformation