Disk space report of remote computer/servers through powershell

Param (
$computers = (Get-Content  “C:\Scripts\Computers.txt”)

$Title=”Hard Drive Report to HTML”

#embed a stylesheet in the html header
$head = @”
–></mce:style><style _mce_bogus=”1″><!–

#define an array for html fragments

#get the drive data
$data=Get-WmiObject -Class Win32_logicaldisk -filter “drivetype=3” -computer $computers

#group data by computername
$groups=$Data | Group-Object -Property SystemName

#this is the graph character

#create html fragments for each computer
#iterate through each group object
ForEach ($computer in $groups) {
    #define a collection of drives from the group object
    #create an html fragment
    $html=$drives | Select @{Name=”Drive”;Expression={$_.DeviceID}},
    @{Name=”SizeGB”;Expression={$_.Size/1GB  -as [int]}},
    @{Name=”UsedGB”;Expression={“{0:N2}” -f (($_.Size – $_.Freespace)/1GB) }},
    @{Name=”FreeGB”;Expression={“{0:N2}” -f ($_.FreeSpace/1GB) }},
      $UsedPer= (($_.Size – $_.Freespace)/$_.Size)*100
      $UsedGraph=$g * ($UsedPer/2)
      $FreeGraph=$g* ((100-$UsedPer)/2)
      #I’m using place holders for the < and > characters
      “xopenFont color=Redxclose{0}xopen/FontxclosexopenFont Color=Greenxclose{1}xopen/fontxclose” -f $usedGraph,$FreeGraph
    }} | ConvertTo-Html -Fragment 
    #replace the tag place holders. It is a hack but it works.
    $html=$html -replace “xopen”,”<”
    $html=$html -replace “xclose”,”>”
    #add to fragments
    #insert a return between each computer
} #foreach computer

#add a footer
$footer=(“<br><I>Report run {0} by {1}\{2}<I>” -f (Get-Date -displayhint date),$env:userdomain,$env:username)

#write the result to a file
ConvertTo-Html -head $head -body $fragments | Out-File c:\Report.htm

#Require Powershell version 2.0


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s