Can someone help me to transpose row into colums. Need to transpose MachineName into columns.
Endtime must be sorted.
<#MachineName, TotalDataSizeBytes, A
Start by finding all relevant machine names, we'll need those later:
$Rows = Import-Csv d:\report3.csv
$MachineNames = $Rows |Select-Object -ExpandProperty MachineName |Sort -Unique
Next up, group all entries by Endtime, and add the values from all rows that are grouped together into a single object:
$ConsolidatedRows = $Rows |Group-Object EndTime |ForEach-Object {
$NewRowProperties = @{ EndTime = [DateTime]::Parse($_.Name) }
foreach($Row in $_.Group)
{
$NewRowProperties.Add($Row.MachineName,$Row.TotalDataSizeBytes)
}
New-Object psobject -Property $NewRowProperties
}
And then finally, select the EndTime
property and all the MachineName
-specific properties using the names we grabbed earlier:
$ConsolidatedRows |Select-Object @("EndTime";$MachineNames) |Export-Csv .\finalReport.csv -NoTypeInformation