powershell script to notify if any of the disk goes offline

Kranthi DBA 221 Reputation points

Hi All, I am trying to prepare a script to notify me if one of the disks goes offline. I plan to create this as a SQL job so that the job fails when any of the disks is not accessible. The below variable has the list of drives on the server and I want to the PowerShell test-path command against each value, but I am unable to write code for the same. Any help would be greatly appreciated. $DriveList = @(Invoke-SQLCmd -query "select distinct LEFT(physical_name, 3) from sys.master_files") test-path $DriveList User's image

Thanks in Advance!

A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,111 Reputation points

    If you're just looking for a PowerShell script that runs in loop forever, is this what you're looking for?

    $Drives = "C:\", "X:\"
        $drives | 
            ForEach-Object {
                if (-NOT (test-path $_)){
                    Throw "Path $_ is no longer available"
            Start-Sleep -Seconds 5
    } while ($true)

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more