SubSun
asked on
Need to modify Powershell script
Hello Experts,
I got the attached script from one of the EE post (Thanks to Chris-Dent). I would like to modify the same script to get an output as shown in screen shot by email.
What need to be added?
1, Need to receive the report via email.
2, Percentage used should change to percentage free.
3, The disks which have less than 20% free space should be highlighted.
4, Free space details of mounted volume should be listed in report.
I got the attached script from one of the EE post (Thanks to Chris-Dent). I would like to modify the same script to get an output as shown in screen shot by email.
What need to be added?
1, Need to receive the report via email.
2, Percentage used should change to percentage free.
3, The disks which have less than 20% free space should be highlighted.
4, Free space details of mounted volume should be listed in report.
Get-WmiObject Win32_LogicalDisk -Filter "DriveType='3'" `
-ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt") | `
Format-Table `
@{l="Server";e={$_.SystemName}}, `
@{l="Drive Letter";e={$_.DeviceID}}, `
@{l="Free Space on Disk (GB)";e={"{0:n2}" -f ($_.freespace/1gb)}}, `
@{l="Total Disk Space (GB)";e={"{0:n2}" -f ($_.size/1gb)}}, `
@{l="Percentage Used";e={ "{0:P2}" -f (1 - ([Int64]$_.FreeSpace / [Int64]$_.Size)) }}
report.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
See the report (I have removed the server name portion)
report.JPG
report.JPG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Does the Win32_Volume Class gives the information about mount points?
ASKER
Also Can you explain the following part? suppose if I want to change the 20% to 10% then how do I modify the calculation?
# Convert to HTML and highlight rows less than 20%
$HtmlBody = $VolumeInformation | ConvertTo-Html -Head $Style | %{
If ($_ -Match ".*(\d|1\d)(\.\d*)?\s%.*") {
$_ -Replace "", ""
} Else { $_ }
}
# Convert to HTML and highlight rows less than 20%
$HtmlBody = $VolumeInformation | ConvertTo-Html -Head $Style | %{
If ($_ -Match ".*(\d|1\d)(\.\d*)?\s%.*")
$_ -Replace "", ""
} Else { $_ }
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot for explaining in detail.
I have done some R&D on Win32_volume and found the following code to get the details, but it also takes the DVD drive and throws the error while calculating %, how do we put filter for "DriveType='3'??
Select-Object : Attempted to divide by zero.
At line:2 char:14
+ Select-Object <<<< `
I have done some R&D on Win32_volume and found the following code to get the details, but it also takes the DVD drive and throws the error while calculating %, how do we put filter for "DriveType='3'??
Select-Object : Attempted to divide by zero.
At line:2 char:14
+ Select-Object <<<< `
==============================
Command
==============================
Get-WmiObject Win32_volume -ComputerName Server01 | where {$_.caption -like "*:\*"} | `
Select-Object `
@{n="Server";e={$_.__SERVER}}, `
@{n="Volume";e={$_.caption}}, `
@{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.freespace/1gb)}}, `
@{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.capacity/1gb)}}, `
@{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.capacity) }}
==========================
Result
==========================
Server : Server01
Volume : C:\
Free Space on Volume (GB) : 2.90
Total Space on Volume (GB) : 15.99
Percentage Free : 18.14 %
Server : Server01
Volume : M:\
Free Space on Volume (GB) : 48.03
Total Space on Volume (GB) : 49.99
Percentage Free : 96.08 %
Server : Server01
Volume : C:\mount\Server01\log\
Free Space on Volume (GB) : 65.70
Total Space on Volume (GB) : 67.09
Percentage Free : 97.93 %
Server : Server01
Volume : C:\mount\Server01\mbox_234\
Free Space on Volume (GB) : 18.70
Total Space on Volume (GB) : 200.00
Percentage Free : 9.35 %
Server : Server01
Volume : C:\mount\Server01\mbox_123\
Free Space on Volume (GB) : 22.08
Total Space on Volume (GB) : 253.48
Percentage Free : 8.71 %
Select-Object : Attempted to divide by zero.
At line:2 char:14
+ Select-Object <<<< `
Server : Server01
Volume : E:\
Free Space on Volume (GB) : 0.00
Total Space on Volume (GB) : 0.00
ASKER
OK got it.. :-)
Get-WmiObject Win32_volume -ComputerName server01 | where {(($_.DriveType -like "3") -and ($_.caption -like "*:\*"))} | `
Select-Object `
@{n="Server";e={$_.__SERVER}}, `
@{n="Volume";e={$_.caption}}, `
@{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.freespace/1gb)}}, `
@{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.capacity/1gb)}}, `
@{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.capacity) }}
ASKER
Chris, in HTML result, how do we make the font look small?
ASKER
OK, I got it-- Added the font-size and now my report looks perfect.. :-)
ASKER
Can I align only volume column data to left?.. :-)
Should be able to, that's what the "<col>" tags are for. Try editing the HTML (perhaps in notepad) to see if it'll do what you want?
Chris
ASKER
When I try to align to left all the columns goes left, not able to align the single column,, :(
Hmm how did you add it?
I had something like this in mind.
In the Style:
col.alignleft { text-align: left; }
In the table:
<colgroup>
<col>
<col class="alignleft">
<col>
<col>
<col>
</colgroup>
Although I haven't actually tried it so I can't be sure it works...
Chris
ASKER
:( same issue.. this is not mandatory. but if we can do it, well & good, you can research on it when you get time..:-) I will also do some research on my end..
Hi Chris,
I ran the same script & it throws me the error MS VB Script compilation error.I am a novice in scripting & need your help to get the disk space percentage for all servers using a input file.Please help.
I ran the same script & it throws me the error MS VB Script compilation error.I am a novice in scripting & need your help to get the disk space percentage for all servers using a input file.Please help.
ASKER
1, Its not displaying details of mount points.
2, Some of the volumes which is more than 20% free space also high lighted.
3, Can I have the output inside table, as I shown in the screen shot?