Hi All,
Good Day,
I was trying to achieve the below:
To monitor a network share and its free space so i managed to write a script as below where it maps the drive as a letter queries the free space added few variables to convert the space in & and added to remove decimal and all worked like a charm.
For the above output i wanted to write a event log to capture the free space. Issue here is that there are 2 conditions on the script i mentioned that if the free space is below 20 % write a warning event and if it is below 10% write a critical event.
Issue is that when the space is below 10 both the logs warning & critical are written. Ex if free space is below 9 both critical & warning is written. Ideally script is doing its job correctly.
But i just want only 1 event for below 10 % critical and one warning for below 20 but above 10.
I am not able to figure the exact "if criteria" to ignore the 20 % if it is below 10 % and want only 1 event for below 10 and not 2
Can anyone tell me what am i missing here ?
$share="\\10.154.139.146\My_Share"
$nwobj=new-object -comobject WScript.Network
$status=$nwobj.mapnetworkdrive("Z:",$share)
$drive=get-psdrive Z
$gb=(1024 * 1024 * 1024)
$free=($drive.free) /$gb
$used=($drive.used) /$gb
$total=($free+$used)
$free%=($free/$total*100)
$free=([math]::Round($free))
Write-Output "Share $share has free space of $free%"
$status=$nwobj.removenetworkdrive("Z:")
If ($free -lt 10) {Write-EventLog -LogName Application -Source "Network Share Monitoring" -EntryType Error
-EventID 210 -Message "The Share $Share has disk space below 20 % and Current value is $free%"}
If ($free -lt 20) {Write-EventLog -LogName Application -Source "Network Share Monitoring" -EntryType
Warning -EventID 210 -Message "The Share $Share has disk space below 20 % and Current value is $free%"}
Event viewer:
Gautam.75801