Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Below is the existing data I have in my csv file

"Server","Disk ###","Status","Size","Free"
"s1","Disk 0","Online","100 GB","1024 KB"
"s1","Disk 1","Online","6144 MB","1024 KB"
"s1","Disk 2","Online","200 GB","1024 KB"
"s1","Disk 3","Online","10 GB","1024 KB"


and below is the additional column which I want to append getting from get-disk command need to add at the end after Free column



TotalSize
---------
100.00 GB
6.00 GB
200.00 GB
10.00 GB


Getting output like

<pre>"Server","Disk ###","Status","Size","Free","TotalSize"
"s1","Disk 0","Online","100 GB","1024 KB","Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"
"s1","Disk 1","Online","6144 MB","1024 KB","Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"
"s1","Disk 2","Online","200 GB","1024 KB","Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"
"s1","Disk 3","Online","10 GB","1024 KB","Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"


Please let me know what I am missing here



What I have tried:

PowerShell
$dataa= Get-Disk | Select-Object -Property @{n="TotalSize";e={'{0:n2} GB' -f ($_.Size / 1GB)}} | ft

Import-Csv -path c:\infile.csv |
Select-Object *,@{Name='TotalSize';Expression={$dataa}} | 
Select-Object "Server","Disk ###","Status","Size","Free", "TotalSize" |
Export-Csv -path C:\Outfile.csv -NoTypeInformation
Posted
Comments
Richard MacCutchan 1-Oct-21 7:06am    
You should try to debug your code by printing the intermediate values of each statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900