HARD DISK MONITORING

Add-on: Powershell scripts

1. Use of detected disk status information in Powershell

The following script gets hard disk status information from Hard Disk Sentinel by WMI function and displays the details.

Thanks to Mitchell K. for the script and example.

#### Code Start

$HdInfo = Get-WmiObject -Query "select * from hdsentinel" -Namespace "root\wmi" 
$Output = @()
foreach($Hd in $HdInfo)
{
    $SmartPsObject = @()
    foreach($Attribute in ($Hd.SMART -split ([char]13)))
    {
        if($Attribute -ne '')
        {
            $AttArr = $Attribute -split ','
            $SmartPsObject += (New-Object PSObject -Property @{ Number = $AttArr[0]
                                                                Attribute = $AttArr[1]
                                                                Threshold = $AttArr[2]
                                                                Value = $AttArr[3]
                                                                Worst = $AttArr[4]
                                                                Data = $AttArr[5]})
        }
    }
    $Properties = Get-Member -InputObject $Hd -Name "__*" | Select -ExpandProperty Name
    $Hd | Add-Member -MemberType NoteProperty -Name 'SMARTObject' -Value $SmartPsObject
    $Output += $Hd | Select * -ExcludeProperty $Properties
}

$Output

#### Code End

Hard Disk Sentinel Pro and Powershell example

Hard Disk Sentinel Pro and Powershell SMART example

2. Use Pushover notification service for alerts triggered in Hard Disk Sentinel

The following script can be used to receive Pushover notifications when any hard disk drive / SSD triggers an alert in Hard Disk Sentinel Pro.

Thanks for Kevan L. B. for the script and example.

# Pushover API Documentation
# https://pushover.net/api

# Hard Disk Sentinel Environment Variables
# https://www.hdsentinel.com/help/en/26_c_msg.html

# Test Values
<#
$env:HDS_TimeStamp = '20190220 222023'
$env:HDS_Host = 'COMPUTER'
$env:HDS_Alert = 'Overheat'
$env:HDS_Disk = "Disk: #0 Some Disk"
$env:HDS_Threshold = 'Temperature threshold setting: 42 C'
$env:HDS_Health = 'Some Disk 100%'
#>

$HDSDateTimeFormat = 'yyyyMMdd HHmmss'

$HDSDateTime = ([DateTime]::ParseExact($env:HDS_TimeStamp, $HDSDateTimeFormat, [CultureInfo]::InvariantCulture))

$PushoverApiUri = 'https://api.pushover.net/1/messages.json'

$PushoverTimestamp = ([DateTimeOffset]($HDSDateTime.ToUniversalTime())).ToUnixTimeSeconds()

$PushoverRequest = @{
    token = 'redacted'
    user = 'redacted'
    message = "$env:HDS_Disk`n$env:HDS_Threshold`n`nOverall Disk Health:`n$env:HDS_Health"
    title = "$env:HDS_Host`: $env:HDS_Alert"
    timestamp = $PushoverTimestamp
}

Invoke-RestMethod -Method Post -Uri $PushoverApiUri -Body $PushoverRequest

The command configured in Hard Disk Sentinel to produce the alert (specifid at Configuration -> Operations -> Run external application or batch file):

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Unrestricted -File "C:\Scripts\HDSentinelPushoverAlert.ps1"

The Alternative for NET SEND forum topic suggested a method to use Pushover but I just wanted to use PowerShell without the need for curl so that no additional tools were required and so that I had more control over the output.

Here is a screenshot what an alert looks like on the phone using the script and Pushover application registration:

Hard Disk Sentinel Pro and Powershell example to Pushover notifications

Did you make any scripts, tools, add-ons which may be useful? Please send an e-mail so it can be shared to help other users.

 

Navigation

Hard Disk Sentinel Home

News

Products

Store

Support

Partners

Useful links

Download Hard Disk Sentinel

Frequently asked questions

Knowledge base

Discussion forum

Contact us

Privacy policy

Resources

Q&A Knowledge Base

Testimonials

Use Case

HDSentinel on Facebook

HDD Monitoring Blog

About

Newsletter

Enter your e-mail address to receive news, tips, updates and special offers about Hard Disk Sentinel software. More ...

Your e-mail address is kept securely (see our privacy policy).


© 2024 H.D.S. Hungary. All Rights Reserved.

Software for hard disk monitoring and data protection