Key takeaways
- Proactive SSD monitoring: The script enables early detection of SSD wear and potential failures, crucial for maintaining system performance and data integrity.
- Customizable thresholds: It allows for setting a wear level threshold, offering flexibility in defining what constitutes an SSD nearing its end of life.
- Administrator access required: Running the script requires Administrator privileges to access detailed disk information.
- Compatibility and requirements: It’s designed for Windows 10 and Server 2016 onwards, ensuring compatibility with modern Windows environments.
- Automatable and integratable: The script can be scheduled for regular execution and integrated into broader IT management systems like NinjaOne.
- No external tools needed: It uses PowerShell and internal Windows commands, eliminating the need for third-party SSD health monitoring tools.
- Critical for IT health: Regularly running this script is vital for IT professionals and MSPs to preemptively address SSD issues.
- Comprehensive reporting: The script provides detailed information on SSD wear level, temperature, and write errors, offering a thorough health overview.
- Prevents data loss: By identifying SSDs at risk of failing, the script helps in planning replacements or backups, preventing potential data loss.
- Enhances IT decision making: The information provided by the script aids in making informed decisions about hardware maintenance and upgrades.
Solid State Drives (SSDs) have become a cornerstone in modern computing, offering faster data access speeds and reliability compared to traditional hard drives. However, like all technology, SSDs are not immune to wear and potential failure. For IT professionals and Managed Service Providers (MSPs), preemptively identifying SSD health issues is crucial to maintaining system reliability and data integrity.
Background
The PowerShell script in question is designed to assess the health of SSDs in a Windows environment. It’s a vital tool for IT professionals and MSPs, enabling them to proactively monitor the wear level and error rates of SSDs. This preemptive approach is critical in averting data loss and ensuring system performance.
The script:
#Requires -Version 5.1 <# .SYNOPSIS Conditional script that helps determine if an SSD drive is failing or has failed. .DESCRIPTION Conditional script that helps determine if an SSD drive is failing or has failed. A wear % of 100% indicates that the estimated wear level as been reached. Do note that some drives don't report all the needed details to the OS. This can be caused by a RAID card, settings in the BIOS, or the drive it self. .PARAMETER WearLevelPercentMax The max estimated wear level percentage to fail at. The default is 80 %. .EXAMPLE -WearLevelPercentMax 90 Fail if SSD is found to have used 90% of its estimated wear leveling. .OUTPUTS None .NOTES Minium Supported OS: Windows 10, Server 2016 Release Notes: Renamed script and added Script Variable support By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use. Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA). #> [CmdletBinding()] param ( [int] $WearLevelPercentMax = 80 ) begin { if ($env:WearLevelPercentMax) { $WearLevelPercentMax = $env:WearLevelPercentMax } function Write-UnhealthyDisk { param([PSObject[]]$Disks) process { $Disks | ForEach-Object { try { $PhysicalDisk = Get-PhysicalDisk -DeviceNumber $_ | Select-Object FriendlyName, DeviceId, MediaType, OperationalStatus, HealthStatus $StorageReliabilityCounters = Get-PhysicalDisk -DeviceNumber $_ | Get-StorageReliabilityCounter | Select-Object Temperature, WriteErrorsTotal, Wear Write-Host "$($PhysicalDisk.FriendlyName)" Write-Host "DeviceId: $($PhysicalDisk.DeviceId) | Type: $($PhysicalDisk.MediaType) | Status: $($PhysicalDisk.OperationalStatus) | Health: $($PhysicalDisk.HealthStatus)" Write-Host "Temp: $($StorageReliabilityCounters.Temperature) C° | Total Write Errors: $($StorageReliabilityCounters.WriteErrorsTotal) | Wear: $($StorageReliabilityCounters.Wear)%" Write-Host "" Write-Output 1 } catch { # Skip this drive Write-Output 0 } } | Measure-Object -Sum | Select-Object -ExpandProperty Sum } } function Test-IsElevated { $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() $p = New-Object System.Security.Principal.WindowsPrincipal($id) $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) } } process { if (-not (Test-IsElevated)) { Write-Error -Message "Access Denied. Please run with Administrator privileges." exit 1 } # Get all disks $Disks = Get-PhysicalDisk # Get any SSD's that have Write Errors, to hot, or Wear level over 10% $UnhealthySSDDisks = $Disks | Where-Object { $_.MediaType -like "SSD" -and $_.PhysicalLocation -notlike "*.vhd*" } | Get-StorageReliabilityCounter | Where-Object { ( $null -ne $_.WriteErrorsTotal -and $_.WriteErrorsTotal -ge 1 # Any amount for an SSD is a cause for concern ) -or ( $null -ne $_.Wear -and # The storage device wear indicator, in percentage. At 100 percent, the estimated wear limit has been reached. # https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-storagereliabilitycounter $_.Wear -ge $WearLevelPercentMax ) } $DeviceIds = $UnhealthySSDDisks | Sort-Object -Property DeviceId -Unique | Select-Object -ExpandProperty DeviceId $DriveCount = Write-UnhealthyDisk -Disks $DeviceIds if ($DeviceIds.Count -and $DriveCount) { Write-Host "WARNING: $($DeviceIds.Count) disks were found with wear level above $WearLevelPercentMax%." exit 1 } Write-Host "No disks were found with wear level above $WearLevelPercentMax%." exit 0 } end { }
Access 300+ scripts in the NinjaOne Dojo
Detailed breakdown
The script operates in several stages:
- Parameter configuration: It starts by defining a parameter WearLevelPercentMax, defaulting to 80%. This represents the threshold at which an SSD is considered to be wearing out.
- Environmental check: The script checks if it’s run with Administrator privileges, a necessity for accessing physical disk information.
- Health assessment: It then retrieves information about each physical disk, focusing on SSDs, and evaluates their wear and error rates. It specifically looks for write errors and a wear percentage greater than the specified threshold.
- Reporting: The script outputs the health status of each SSD, detailing wear level, temperature, and write errors.
- Decision making: Based on this information, it issues warnings or confirms the healthy status of the SSDs.
Potential use cases
An IT administrator at a medium-sized enterprise uses this script as part of routine maintenance. They schedule it to run monthly, ensuring early detection of SSD wear and preventing unexpected failures that could disrupt business operations.
Comparisons
Traditionally, SSD health is monitored using manufacturer-specific tools or third-party software. While these tools are effective, the PowerShell script offers a more integrated and scriptable approach, allowing for automation and custom threshold settings.
FAQs
- Can this script run on any version of Windows?
- It requires Windows 10 or Server 2016 and above.
- What if my SSD doesn’t support reporting wear level?
- Some SSDs may not report all necessary details, possibly due to hardware or configuration limitations.
- Is it safe to use in a production environment?
- Yes, but it’s recommended to test it in a controlled environment first.
Implications
Incorrect interpretation of the script’s output can lead to premature SSD replacements or neglecting a failing drive, both costly in different ways. Understanding the script’s assessment and thresholds is key to informed decision-making.
Recommendations
- Run regularly: Schedule the script to run periodically for ongoing monitoring.
- Contextual analysis: Consider other health indicators and usage patterns alongside the script’s findings.
- Stay updated: Ensure your PowerShell version and SSD firmware are up to date.
Final thoughts
In the context of SSD health monitoring, a tool like NinjaOne can complement the script’s capabilities. NinjaOne provides comprehensive IT management solutions, including monitoring and alerting, which can integrate seamlessly with scripts like this for a more holistic approach to IT infrastructure health. This script is a step towards proactive system management, a principle that aligns with NinjaOne’s philosophy of preventing issues before they become problems.