Search code examples
excelpowershellexportcustomization

PowerShell export "Get-volume" to excel/csv


I used the below one it gives somewhat different in excel ,please help me on this

#Disk Space
Get-Volume
$results = Get-Volume | Export-Csv -Path C:\temp\software1.csv

Note: I need health check , Drive Name, Free space , size, disk type in excel

Thanks in advance friends :)


Solution

  • Generally speaking, when you run a powershell command it only shows what sections are deemed as important. If you take the same command and pipe it to format-list (or "ft" for short) you will get everything.

    Get-Volume | ft
    

    When exporting it exports everything. Also, you need to add the paramater -NoTypeInformation to get rid of the first row.

    To only get certain values, you will just pipe it using select.. something like this:

    Get-Volume | select HealthStatus, DriveLetter, SizeRemaining,DriveType | Export-Csv -NoTypeInformation -Path C:\temp\software1.csv
    

    Also, there is no need to do $results = get-volume... This pushes the output into the variable $results. This would be applicable if you wanted to recall the variable later. So, you could also do something like this..

    $results = Get-Volume 
    $results | select HealthStatus, DriveLetter, SizeRemaining, DriveType | Export-Csv -NoTypeInformation -Path C:\temp\software1.csv