Smart HDD Check

Here is another little script that checks the S.M.A.R.T Parameters for a HDD and checks the status.

Also Returns the output so can analyse further.

As always, if you would like to buy me a beer you can do so using this link.

paypal donate button[5]

<#	
	.NOTES
	===========================================================================
	 Created on:   	21/02/2016 12:24 AM
	 Created by:   	Jake Paterrnoster (jake@www.jcpit.com.au)
	 Organization: 	JCPIT Support (www.jcpit.com.au)
	 Filename:     	CheckHDDSmart.ps1
	===========================================================================
	.DESCRIPTION
		Powershell script to check the S.M.A.R.T stats from a HDD into GFI Max.
#>

clear-host

function PathByService($serviceName)
{
	# Find service and use path to locate files
	$ServiceObject = Get-WmiObject Win32_Service | Where-Object { $_.Name -eq $serviceName }
	
	if ($ServiceObject)
	{
		$ServicePath = Split-Path $ServiceObject.PathName.Replace('"', "") -Parent
		return $ServicePath
	}
	else
	{
		Write-Host "Cant find service $serviceName"
		return $null
	}
}

# Find "Advanced Monitoring Agent" service and use path to locate files
$MaxPath = PathByService("Advanced Monitoring Agent")
$ProgDir = "smart101"
$ProgURL = "http://retired.beyondlogic.org/solutions/smart/smart101.zip"
$ProgDownload = $ProgURL.Substring($ProgURL.LastIndexOf("/") + 1)
$ProgExe = "smart.exe"

# If We found the AMA folder
if ($MaxPath -ne $null)
{
	
	#If Program EXE not found, Download and extract the zip
	if (-not (Test-Path "$MaxPath\$ProgDir\$ProgExe"))
	{
		New-Item -ItemType directory -Path "$MaxPath\$ProgDir" | Out-Null
		(New-Object Net.WebClient).DownloadFile($ProgURL, "$MaxPath\$ProgDownload"); (new-object -com shell.application).namespace("$MaxPath\$ProgDir").CopyHere((new-object -com shell.application).namespace("$MaxPath\$ProgDownload").Items(), 16)
	}
	
	$pinfo = New-Object System.Diagnostics.ProcessStartInfo
	
	$pinfo.FileName = "$MaxPath\$ProgDir\$ProgExe"
	$pinfo.RedirectStandardOutput = $true
	$pinfo.UseShellExecute = $false
	$pinfo.Arguments = ""
	
	$p = New-Object System.Diagnostics.Process
	$p.StartInfo = $pinfo
	$p.Start() | Out-Null
	$p.WaitForExit()
	
	$stdout = $p.StandardOutput.ReadToEnd()
	
	Write-Host "$stdout"
	if ($p.ExitCode -ne 0)
	{
		Exit 1000
	}
	Else
	{
		Exit 0
	}
	
}
Else
{
	Write-Host "Agent Path not found!"
	Exit 2000
}