01 Install NetApp PowerShell Toolkit

The NetApp PowerShell Toolkit (PSTK) is available on the PowerShell Gallery. It provides ONTAP-specific cmdlets wrapping both REST and ZAPI endpoints.

powershell
# Install from PowerShell Gallery
Install-Module -Name NetApp.ONTAP -Scope CurrentUser

# Import the module
Import-Module NetApp.ONTAP

# Verify installation
Get-Command -Module NetApp.ONTAP | Select-Object -First 10

02 Connect to ONTAP Cluster

powershell
$ClusterIP   = "192.168.1.100"
$Credentials = Get-Credential  # Prompts securely

# Connect โ€” skipping cert check (use -Https with valid cert in prod)
Connect-NcController -Name $ClusterIP -Credential $Credentials

# Verify connection
Get-NcController

03 Volume Operations

powershell ยท List Volumes
# All volumes
Get-NcVol

# Filtered by SVM with selected properties
Get-NcVol -Vserver "svm0" |
    Select-Object Name, TotalSize, Used, State |
    Format-Table -AutoSize

# Export to CSV for reporting
Get-NcVol |
    Select-Object Name, TotalSize, Used, Vserver, State |
    Export-Csv -Path "volumes_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation
powershell ยท Create Volume
New-NcVol `
    -Name      "my_new_vol" `
    -Vserver   "svm0" `
    -Aggregate "aggr1" `
    -Size      "10g" `
    -JunctionPath "/my_new_vol" `
    -SpaceReserve "none"

Write-Host "Volume created successfully" -ForegroundColor Green
powershell ยท Resize Volume
# Resize to 20 GB
Set-NcVolSize -Name "my_new_vol" -Vserver "svm0" -NewSize "20g"

# Verify
Get-NcVol -Name "my_new_vol" | Select-Object Name, TotalSize

04 Snapshot Management

powershell
# Create a snapshot
New-NcSnapshot -VolumeName "my_vol" -SnapshotName "snap_20240801"

# List snapshots for a volume
Get-NcSnapshot -VolumeName "my_vol" |
    Select-Object Name, Created |
    Format-Table -AutoSize

# Delete a snapshot
Remove-NcSnapshot -VolumeName "my_vol" -SnapshotName "snap_old"

# Bulk cleanup: delete snapshots older than 30 days
$cutoff = (Get-Date).AddDays(-30)
Get-NcSnapshot -VolumeName "my_vol" |
    Where-Object { $_.Created -lt $cutoff } |
    ForEach-Object { Remove-NcSnapshot -VolumeName "my_vol" -SnapshotName $_.Name }

05 Invoke-RestMethod (Direct API)

Use Invoke-RestMethod to call ONTAP REST endpoints without PSTK โ€” great for newer endpoints or CI/CD pipelines where installing PSTK isn't ideal.

powershell
$base    = "https://192.168.1.100/api"
$creds   = [Convert]::ToBase64String(
              [Text.Encoding]::ASCII.GetBytes("admin:Password123"))
$headers = @{
    Authorization  = "Basic $creds"
    "Content-Type" = "application/json"
}

# Skip SSL verify (dev only)
if (-not ([System.Management.Automation.PSTypeName]'TrustAll').Type) {
    Add-Type @"
using System.Net; using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class TrustAll {
    public static void SetCallback() {
        ServicePointManager.ServerCertificateValidationCallback =
            (s,c,ch,e) => true;
    }
}
"@
    [TrustAll]::SetCallback()
}

# Get cluster info
$result = Invoke-RestMethod "$base/cluster?fields=name,version" -Headers $headers
Write-Host "Cluster: $($result.name) | ONTAP: $($result.version.full)"

# List volumes via REST
$vols = Invoke-RestMethod "$base/storage/volumes?fields=name,state,size" -Headers $headers
$vols.records | Format-Table name, state, size

06 Error Handling

powershell
try {
    New-NcVol -Name "test_vol" -Vserver "svm0" `
              -Aggregate "aggr1" -Size "5g" -ErrorAction Stop

    Write-Host "[OK] Volume created" -ForegroundColor Green
}
catch {
    Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
    # Log to file
    $_ | Out-File -FilePath "errors.log" -Append
}
finally {
    Disconnect-NcController
}