Storage Admin Hub
Automation · Automation guide

PowerShell health check and CSV inventory

Call ONTAP REST for every cluster in a dummy CSV, export daily health and volume inventories, and handle pagination and TLS.

Scope

Educational ONTAP 9 example. Confirm platform, protocol and release compatibility in the linked documentation.

Scenario

Example: a Windows or PowerShell 7 monitoring host contacts two fictional clusters. daily-health.ps1 exports one CSV row per cluster with node, aggregate, volume and SnapMirror status. inventory-report.ps1 exports each volume with SVM, state, size and usage. Both load inventory.csv through Import-Csv and follow ONTAP REST next-page links.

About the command and output examples

Names, addresses and results are illustrative. Commands have not been executed against a live storage system or SAN switch for this publication. Confirm syntax and compatibility for your release, then rehearse in an approved lab. Existing-data recovery and destructive changes need an environment-specific plan. Read the editorial standards.

01Prepare PowerShell 7, account and trust

  1. Install PowerShell 7 and download daily-health.ps1, inventory-report.ps1 and inventory.csv into one directory. Set the CSV Address column to the cluster management IPs. For each cluster, allow HTTPS management access from this host, grant a dedicated account read access to the four REST resources, and verify your ONTAP version supports the requested fields.
  2. Install the ONTAP issuing CA certificate into the trusted certificate store on the monitoring host. If certificates identify DNS names rather than IPs, replace addresses in inventory with those DNS names and ensure their certificates match. The scripts do not bypass TLS certificate checking.
  3. Run Get-Credential interactively; this example shares one account/password across entries. If clusters need different identities, separate inventory runs or adapt credential lookup by cluster. Keep CSV inventories free of passwords.
PowerShell 7 interactive example
Cluster,Address
lab-a,192.0.2.10
lab-b,192.0.2.11

$credential = Get-Credential
./daily-health.ps1 -InventoryPath ./inventory.csv -Credential $credential -OutDir ./reports -CapacityThreshold 85
Acceptance check

The prompt requests credentials; reports/health-UTC.csv contains one row for each cluster and a Status of OK, WARN or ERROR.

02Understand every check

  1. The script requests /api/cluster/nodes and warns when a node state differs from up, or no nodes are returned. It checks aggregate block_storage used/size and volume space used/size against the supplied percentage threshold. It warns on volumes whose state differs from online and relationships with healthy=false.
  2. Status ERROR means one of the REST calls or authentication failed for that cluster; Details contains the exception. Status WARN lists threshold or state findings. Status OK means only these four API checks found no exception. It does not assert HA readiness, EMS status, all SnapMirror RPOs or application health.
  3. The client requests 1000 records per page and follows _links.next.href while checking the host and /api/ prefix. Confirm that your monitoring account can read all pages. Review limits for your workload and add checks for lag and health alerts before treating the CSV as a complete operational verdict.
Review output; replace example timestamp
Import-Csv ./reports/health-20260101T070000Z.csv | Format-Table Cluster,Status,Details -Wrap
./daily-health.ps1 -InventoryPath ./inventory.csv -Credential $credential -CapacityThreshold 80
Acceptance check

A deliberately offline test volume or low threshold produces WARN and a nonzero process exit.

03Export a detailed volume inventory

  1. The second script reads the same inventory.csv with Import-Csv and calls /api/storage/volumes for each cluster. For every returned volume it writes Cluster, SVM, Volume, State, SizeGiB and UsedGiB. Check the output against System Manager and handle the CSV as operational metadata.
  2. Run the example below from PowerShell 7. If one cluster fails, this inventory script stops rather than writing a deceptively complete list. It follows all REST pages and refuses a pagination URL that changes the host.
PowerShell 7 inventory export
$credential = Get-Credential
./inventory-report.ps1 -InventoryPath ./inventory.csv -Credential $credential -OutFile ./volume-inventory.csv
Import-Csv ./volume-inventory.csv | Select-Object -First 5
Acceptance check

Volume rows include both clusters, and record counts agree with a filtered System Manager view.

04Schedule safely and diagnose failures

  1. For unattended runs, create a restricted scheduled-task account and retrieve a secret from an approved Windows secret store or managed identity workflow inside a small wrapper that builds PSCredential. Get-Credential is interactive and cannot serve an unattended task. Avoid plaintext passwords, embedded script credentials, and disabling certificate checks.
  2. Create a Windows Task Scheduler daily trigger and action: pwsh.exe -NoProfile -File C:\Ops\run-health.ps1, where the wrapper obtains a credential and invokes daily-health.ps1. Grant the account write access to the report directory. Capture exit code and alert on WARN/ERROR or missing CSV.
  3. For HTTP 401/403 check account permissions and REST role mapping; for certificate errors check CA trust and hostname; for timeouts check the cluster-management LIF and firewall; for unexpected empty output check API field permissions and inventory header spelling.
Acceptance check

A scheduled run creates a fresh CSV for all clusters, and task monitoring detects nonzero exits.

Official references and further reading

Choose the matching release in the vendor documentation before using a command or design. References open on the publisher’s website; linked material remains with its publisher.