Here is the code so far. Any help is much appreciated.
$TotalGB = @{ Name = "Capacity(GB)"; expression = { [math]::round(($_.Capacity/ 1073741824), 2) } }
$FreeGB = @{ Name = "FreeSpace(GB)"; expression = { [math]::round(($_.FreeSpace / 1073741824), 2) } }
$FreePerc = @{ Name = "Free(%)"; expression = { [math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100), 0) } }
function get-mountpoints
{
$volumes = Get-WmiObject -computer $server win32_volume | Where-object { $_.DriveLetter -eq $null }
$volumes | Select SystemName, Label, Flag, $TotalGB, $FreeGB, $FreePerc | where { $_.Label -like '*Logs' } | Format-Table -AutoSize
}
$servers = (Get-Content .\servers.txt)
foreach ($server in $servers)
{
get-mountpoints
}
Need to send email only when free space is under 500GB
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Need to send email only when free space is under 500GB
Actually I'm more concerned with how I do it with the logic. I want it to create an email when free space is under 500GB. I just haven't put the email part of the code in yet.
Re: Need to send email only when free space is under 500GB
What have you tried? Have you read the help I posted?miketartaglia wrote:Actually I'm more concerned with how I do it with the logic. I want it to create an email when free space is under 500GB. I just haven't put the email part of the code in yet.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Need to send email only when free space is under 500GB
- $TotalGB = @{ Name = "Capacity(GB)"; expression = { [math]::round(($_.Capacity/ 1073741824), 2) } }
- $FreeGB = @{ Name = "FreeSpace(GB)"; expression = { [math]::round(($_.FreeSpace / 1073741824), 2) } }
- $FreePerc = @{ Name = "Free(%)"; expression = { [math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100), 0) } }
- function get-mountpoints
- {
- $volumes = Get-WmiObject win32_volume | Where-object { $_.DriveLetter -eq 'c:' }
- $volumes | Select SystemName, Label, Flag, $TotalGB, $FreeGB, $FreePerc
- }
- PS H:\> ((get-mountpoints).'FreeSpace(GB)' -lt 500)
- True
- PS H:\> ((get-mountpoints).'FreeSpace(GB)' -lt 300)
- False
- PS H:\>
- if((get-mountpoints).'FreeSpace(GB)' -lt 500){ send email}
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Need to send email only when free space is under 500GB
Revised code. Sends the email no matter what.
$TotalGB = @{ Name = "Capacity(GB)"; expression = { [math]::round(($_.Capacity/ 1073741824), 2) } }
$FreeGB = @{ Name = "FreeSpace(GB)"; expression = { [math]::round(($_.FreeSpace / 1073741824), 2) } }
$FreePerc = @{ Name = "Free(%)"; expression = { [math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100), 0) } }
function get-mountpoints
{
$volumes = Get-WmiObject -computer $server win32_volume | Where-object { $_.DriveLetter -eq $null }
$volumes | Select SystemName, Label, Flag, $TotalGB, $FreeGB, $FreePerc | where { $_.Label -like '*Logs' } | Format-Table -AutoSize
}
$servers = (Get-Content .\servers.txt)
foreach ($server in $servers)
{
get-mountpoints
if ((get-mountpoints).'FreeSpace(GB)' -lt 500)
{
$email = @{
From = "DiskSpaceReport@domain.com"
To = "userid@domian.COM"
Subject = "LOG ALERT for $server"
SMTPServer = "smtp.domian.com"
Body = "Server log volume is filling up"
}
send-mailmessage @email
}
}
$TotalGB = @{ Name = "Capacity(GB)"; expression = { [math]::round(($_.Capacity/ 1073741824), 2) } }
$FreeGB = @{ Name = "FreeSpace(GB)"; expression = { [math]::round(($_.FreeSpace / 1073741824), 2) } }
$FreePerc = @{ Name = "Free(%)"; expression = { [math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100), 0) } }
function get-mountpoints
{
$volumes = Get-WmiObject -computer $server win32_volume | Where-object { $_.DriveLetter -eq $null }
$volumes | Select SystemName, Label, Flag, $TotalGB, $FreeGB, $FreePerc | where { $_.Label -like '*Logs' } | Format-Table -AutoSize
}
$servers = (Get-Content .\servers.txt)
foreach ($server in $servers)
{
get-mountpoints
if ((get-mountpoints).'FreeSpace(GB)' -lt 500)
{
$email = @{
From = "DiskSpaceReport@domain.com"
To = "userid@domian.COM"
Subject = "LOG ALERT for $server"
SMTPServer = "smtp.domian.com"
Body = "Server log volume is filling up"
}
send-mailmessage @email
}
}
Re: Need to send email only when free space is under 500GB
When you copy scripts and attempt to use them without understanding what they do you will likely always get into this corner.
The following is effectively what you are trying to do. YOu will need to learn enough PowerShell to debug this as I expect the filter may not be correct for your installation.
Notice that most of your coed is either not used or not required to send the mail you are trying to send.
The following is effectively what you are trying to do. YOu will need to learn enough PowerShell to debug this as I expect the filter may not be correct for your installation.
- ]$servers = Get-Content .\servers.txt
- foreach ($server in $servers) {
- if ($volume = Get-WmiObject -computer $server win32_volume -Filter 'DriveLetter IS Null AND Label like "%logs%"') {
- if ($volume.Freespace -lt 500Gb) {
- $body = 'Server log volume is filling up'
- Send-MailMessage -Subject "LOG ALERT for $server" -Body $body -From DiskSpaceReport@bjs.com -To mtartaglia@BJS.COM -SMTPServer smtp.bjs.com
- }
- }
- }