1

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 :)

ManojKiran A
  • 5,896
  • 4
  • 30
  • 43
MOHIDEEN
  • 13
  • 2
  • 3
    You can use [Select-Object](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7) to select the properties of the objects you need. Please read the complete help including the examples to learn hot to use it. – Olaf Jun 08 '20 at 08:00

2 Answers2

1

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
0

Keep in mind you need to have the Import-Excel Module loaded but you should be able to use this to output to Excel.

 #check-DiskSpace_FSs.ps1

 import-module activedirectory
 $dc = "domainController09"
 $currentDate = get-date -Format yyyyMMdd_HHmm
 $path = "\\UNC\export\FileServer_DiskSpace\FileServer_DiskSpace_$currentDate.xlsx" 
 $smtpServer = "10.10.10.10"
 $from = "me@somewhere.com"
 $to = "me@somewhere.com"
 $subject = "Server FS diskspace - $date"

 $ServerFSs = get-adcomputer -Server $dc -SearchBase "OU=fs,OU=Server,DC=somewhere,DC=com" -filter * | select name | sort Name
 
 $DriveSize = foreach ($FS in $somewhereFSs) 
   { 
     get-WmiObject win32_logicaldisk -ComputerName $FS.name -Filter "Drivetype=3" | select SystemName,DeviceID,@{n="TotalSize(GB)";e={$_.Size / 1gb -as      [int] }}`
     ,@{n="FreeSize(GB)";e={$_.freespace / 1gb -as [int] }}`
     ,@{n="FreeSize(%)";e={[int]($_.Freespace*100/$_.Size)}},VolumeName | Export-Excel -Path $path -append -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter
   } 

 Send-Mailmessage -smtpServer $smtpServer -from $from -to $to -subject $subject -Attachments $path -priority High 
shiv
  • 1