How do I get the status, in html format, of the C drive from 150 servers using powershell.

I have this code

Get-WmiObject win32_logicaldisk -Computername remotecomputer

I am trying to get remote server information like remaining space and free space percentage, and show it in HTML file format. There are 150 servers that I want included in the HTML file.

  • What do you mean by “status,” specifically?
    – MDMarra
    Oct 26 '17 at 12:35
  • I mean detail like space storge
    – Mr Hery
    Oct 26 '17 at 15:02
  • Please update your question with the specific items that you want to query.
    – MDMarra
    Oct 26 '17 at 16:18

Put the 150 servers into a variable either directly or by using Get-Content and use Get-Volume and ConvertTo-HTML.

$servers = "server1","server2"
$props = @(
  @{Name="Space";Expression={"$([int]($_.Size / 1024Mb)) GB"}},
  @{Name='SpaceUsed';Expression={"$([int](($_.Size - $_.SizeRemaining) / 1024Mb)) GB"}},
  @{Name="SpaceRemaining";Expression={"$([int]($_.SizeRemaining / 1024Mb)) GB"}},
  @{Name='PercentFull';Expression={"$([int](100 - (($_.SizeRemaining / $_.Size) * 100))) %"}}
Get-Volume -DriveLetter C -CimSession $servers |
  Select-Object -Property $props -ExcludeProperty *cim* |
    ConvertTo-Html |
      Out-File -FilePath $env:temp\ServerCVolumes.html

Edited: Added space remaining %. Cory Knutson posted the % free before I could edit mine.

  • And if you want to make this go faster take a look at powershell remoting.
    – uSlackr
    Oct 27 '17 at 14:48
  • 1
    I already perf tested this, ran it through a 150 server group, took about 4.7 seconds. Using -AsJob parameter drops it to 3.5 seconds. @cory-knutson example was about 15 seconds. Oct 27 '17 at 15:16

This will include the free space percent, and a human readable size in GB

$servers = "server1","server2"
$output = @()

$Servers | ForEach-Object {
    $server = $_

    $output += Get-Volume C -CimSession $_ | 
        Select-Object @{Name="Server";Expression={$server}},`
                        @{Name="PercentFree";Expression={$_.SizeRemaining / $_.Size}},`
                        @{Name="RemainingReadable";Expression={"$($_.SizeRemaining / 1024Mb) GB"}},`

$output | ConvertTo-Html | Out-File C:\Report.html

# OR

$output | Export-Csv -NoTypeInformation -Path C:\report.csv
  • 1
    Does powershell has its own ability to generate graphical views like graph or pie chart showing how much space left (in html file)?
    – Mr Hery
    Oct 27 '17 at 11:49
  • 1
    While that may or may not be possible, that is more than you could expect from a free answer. There may be some custom modules that would head in that direction, but you may be better off just exporting from Powershell to CSV, and making something pretty in Excel. Oct 27 '17 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.