Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

Add server count in powershell

Is it possible to modify the attached powershell to show number of servers finally reported in powerscript ?

Thx
ChkDisk.ps1.txt
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

This should work. I'm assuming you want it added to the e-mail somehow, this adds it as a paragraph above the table.
$diskSpaceReport =  Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" -Computer (Get-Content .\computer.csv) -ErrorAction silentlycontinue |
    Select-Object SystemName,
                  DeviceID,
                  @{Name="Free (%)";Expression={"{0:N0}" -f (($_.freespace /1gb) / ($_.size /1gb) * 100) }},
                  @{Name="Size (GB)";Expression={"{0:N1}" -f($_.size/1gb)}},
                  @{Name="Free (GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} 

$body = @('<p>Disk space report for {0} servers.</p>' -f ($diskSpaceReport | Group-Object SystemName -NoElement | Measure-Object).Count)
$body += $diskSpaceReport | ConvertTo-Html -Fragment

# Remove the extra table added by generating content like this.
$document = (ConvertTo-Html -Body $body | Out-String) -replace '<table>\r?\n</table>\r?\n'

Send-MailMessage -SmtpServer mail1.abc.com -From backupserver@abc.com -To admin@abc.com -Subject 'Servers Disk Space Analysis' -Body $document -BodyAsHtml

Open in new window

Avatar of AXISHK
AXISHK

ASKER

What's the purpose for the following line ? What does it perform ? I have taken out the replace string and I can see the result without problem...  Thx

 $document = (ConvertTo-Html -Body $body | Out-String) -replace '<table>\r?\n</table>\r?\n'
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK

ASKER

Thx
Thanks as well Chris.