NetApp sdcli disk list to CSV with Powershell

#NetApp #sdcli #Powershell

So I have been breaking playing around with Jetstress, NetApp filers and Cisco UCS.  Not have much fun or luck, as I just cant get the damn thing to pass even a simple test.  But that is another story!

I have been looking at sdcli and getting some powershell automation going, and I wanted to find out details of all the disks connected to my severs.  Now sdcli is the worst thing in the word for getting anything decent out, so I wrote the following.  Basically run it on a server with NetApp SnapDrive and it will give you a CSV file with the output of sdcli disk list.  Shweet ;-)   It crude but effective!

Enjoy

Get-SdcliDiskList.ps1

$diskInfo = Invoke-Expression “sdcli disk list”$tmpsdcliDiskListMatrix = @()
ForEach($Item in $DiskInfo){
$tmpItem = $Item.Trim()
$tmpItemSplit = $tmpItem.Split(“:”)
Switch -Wildcard ($tmpItem){
“UNC Path:*”  {$tmpsdcliDiskListMatrix  += $sdcliDiskList
$sdcliDiskList = “” | Select UNCPath, LUNPath, StorageSystem, StorageSystemPath, Type, Diskserialnumber, BackedbySnapshotCopy, Shared, BootOrSystemDisk, SCSIport, Bus, Target, LUN, Readonly, Size, SnapmirrorSource, SnapvaultPrimary, DiskPartitionStyle, CloneSplitRestorestatus, DiskID, VolumeName, Mountpoints, IPAddresses, FCinitiatorWWPN
$sdcliDiskList.UNCPath = $tmpItemSplit[-1]}
“LUN Path:*”                  {$sdcliDiskList.LUNPath = $tmpItemSplit[-1]}
“Storage System:*”            {$sdcliDiskList.StorageSystem = $tmpItemSplit[-1].trim()}
“Storage System Path:*”       {$sdcliDiskList.StorageSystemPath = $tmpItemSplit[-1].trim()}
“Type:*”                      {$sdcliDiskList.Type = $tmpItemSplit[-1].trim()}
“Disk serial number:*”        {$sdcliDiskList.Diskserialnumber = $tmpItemSplit[-1].trim()}
“Backed by Snapshot Copy:*”   {$sdcliDiskList.BackedbySnapshotCopy = $tmpItemSplit[-1].trim()}
“Shared:*”                    {$sdcliDiskList.Shared = $tmpItemSplit[-1].trim()}
“BootOrSystem Disk:*”          {$sdcliDiskList.BootOrSystemDisk = $tmpItemSplit[-1].trim()}
“SCSI port:*”                  {$sdcliDiskList.SCSIport = $tmpItemSplit[-1].trim()}
“Bus:*”                        {$sdcliDiskList.Bus = $tmpItemSplit[-1].trim()}
“Target:*”                     {$sdcliDiskList.Target = $tmpItemSplit[-1].trim()}
“LUN:*”                        {$sdcliDiskList.Lun = $tmpItemSplit[-1].trim()}
“Readonly:*”                   {$sdcliDiskList.Readonly = $tmpItemSplit[-1].trim()}
“Size:*”                       {$sdcliDiskList.Size = $tmpItemSplit[-1].trim()}
“Snapmirror Source:*”          {$sdcliDiskList.SnapmirrorSource = $tmpItemSplit[-1].trim()}
“Snapvault Primary:*”          {$sdcliDiskList.SnapvaultPrimary = $tmpItemSplit[-1].trim()}
“Disk Partition Style:*”       {$sdcliDiskList.DiskPartitionStyle = $tmpItemSplit[-1].trim()}
“Clone Split Restore status:*” {$sdcliDiskList.CloneSplitRestorestatus = $tmpItemSplit[-1].trim()}
“DiskID:*”                     {$sdcliDiskList.DiskID = $tmpItemSplit[-1].trim()}
“Volume Name:*”                {$sdcliDiskList.VolumeName = $tmpItemSplit[-1].trim()}
“*Mount points:*”              {$sdcliDiskList.Mountpoints = $tmpItem.Split(“`t”)[-1].trim()}
“IP Addresses:*”               {$sdcliDiskList.IPAddresses = $tmpItemSplit[-1].trim()}
“FC initiator WWPN:*”          {$sdcliDiskList.FCinitiatorWWPN = $tmpItem.Split(“`t”)[-1].trim()}
}
}

$tmpsdcliDiskListMatrix  | Export-Csv SDCLIDisks.csv -NoTypeInformation -Delimiter “|”

Comments

  1. Export-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.
    At C:\Users\m0132130\get-sdclidisklist.ps1:35 char:38
    + $tmpsdcliDiskListMatrix | Export-Csv <<<< SDCLIDisks.csv -NoTypeInformation -Delimiter "`t"
    + CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo
    mmand

    Does this have proper add-member statements to construct an object?

  2. Hi Joe,

    I’ve same issue and spent little time over it. Apparently it’s because of variable set at top is empty as invoke command didn’t return any value.

    I took other way around and it works like charm to me. Also gives an advantage to run same script for remote servers in domain.
    (provided PSRemoting in enabled –> “Enable-PSRemoting -Force” )

    $diskInfo = invoke-command -computername “<>” -scriptblock { sdcli disk list }
    $diskInfo = @()

    Cheers!
    Avanish

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: