Script to diagram Aggregates, Volumes & Luns within Visio

Done with:

  • PowerShell 2.0
  • Visio 2010 Standard/Premium
  • OnTap 7.3/8.0

Download the NetApp Vision Stencils and extract them to your “C:Users<User name>My DocumentsMy Shapes” directory.  Then install the NetApp OnTap PS Toolkit from the now.netapp.com site (you will need a customer login although it is free).  You will need to import the module by typing “Import-Module DataOntap”. If an error arises and PowerShell doesn’t import that module run “Get-Module -ListAvailable” and make sure DataOntap is in that list.  If its not, make sure you install the OnTap PS Toolkit.

The script you need to run is:  Proper PS1 format here <–Change extension to .ps1

$shpFile1 = "NetApp-Logic-Icons.vss"
$shpFile2 = "NetApp-Equipment-Icons.vss"
$FASName = read-host "Enter the FQDN of your NetApp array"
 If ($FASName -eq "") { Write-Host "No selection made, script now exiting." ; exit }

function connect-visioobject ($firstObj, $secondObj) { 

 $shpConn = $pagObj.Drop($pagObj.Application.ConnectorToolDataObject, 0, 0) 

 #// Connect its Begin to the 'From' shape:
 $connectBegin = $shpConn.CellsU("BeginX").GlueTo($firstObj.CellsU("PinX"))     
 #// Connect its End to the 'To' shape:
 $connectEnd = $shpConn.CellsU("EndX").GlueTo($secondObj.CellsU("PinX")) }

function add-visioobject ($mastObj, $item) {      
 Write-Host "Adding $item"    
 # Drop the selected stencil on the active page, with the coordinates x, y      
 $shpObj = $pagObj.Drop($mastObj, $x, $y)     
 # Enter text for the object      
 $shpObj.Text = $item    
 #Return the visioobject to be used     return $shpObj }

# Create an instance of Visio and create a document based on the Basic Diagram template.
$AppVisio = New-Object -ComObject Visio.Application$docsObj = $AppVisio.Documents
$DocObj = $docsObj.Add("Basic Network Diagram.vst")
# Set the active page of the document to page 1
$pagsObj = $AppVisio.ActiveDocument.Pages $pagObj = $pagsObj.Item(1)

# Load a set of stencils and select one to drop
$stnPath = [system.Environment]::GetFolderPath('MyDocuments') + "My Shapes"
$stnObj1 = $AppVisio.Documents.Add($stnPath + $shpFile1)
$FlexVOLObj = $stnObj1.Masters.Item("FlexVol")
$AggrObj = $stnObj1.Masters.Item("Raid Grp Aggregate Storage")
$LUNObj = $stnObj1.Masters.Item("Cylinder")
$stnObj2 = $AppVisio.Documents.Add($stnPath + $shpFile2)
$FASObj = $stnObj2.Masters.Item("FAS3000 Double controllers")

Connect-NaController $FASName
$allAGGR = Get-NaAggr
$allVols = Get-NaVol
$allLUNs = Get-NaLun

$y = $allAGGR.Count * 1.50 / 2$x = 1.50
$FASObj = add-visioobject $FASObj $FASName

$x = 3.50 $y += 2

Foreach ($aggr in $allAGGR) { 
 $aggrObj = add-visioobject $AggrObj $aggr.Name 
 connect-visioobject $FASObj $aggrObj    
 $y += 1.5         

 Foreach ($volume in $allVols) {     
  If ($volume.ContainingAggregate -eq $aggr.Name) {                     
  $x += 2.50                      
 $volInfo = "Volume Name: " + $volume.Name + "`r`n" + "Total Size (GB): " + "{0:n2}" -f + `
      ($volume.SizeTotal / 1gb) + "`r`n" + "Size Used: " + "{0:n2}" -f ($volume.SizeUsed / 1gb)         
 $FlexVOLObj = add-visioobject $FlexVOLObj $volInfo                                 
 connect-visioobject $aggrObj $FlexVOLObj                        

 Foreach ($lun in $allLUNs) {                     
 $lunVol = $lun.path.split("/")                             
 If ($lunVol[2] -eq $volume.name) {                             
 $x += 1                
 $y += .50                                    
 $lunInfo = "LUN Name: " + $lun.path + "`r`n" + "Total Size (GB): " + "{0:n2}" -f ($lun.Size / 1gb)                 
 $LUNObj = add-visioobject $LUNObj $lunInfo                
 connect-visioobject $FlexVOLObj $LUNObj                                    
 $x -= 1                
 $y -= .50
}
}
}
}         
 $x = 3.50 
 $y += 2.50     }

# Resize to fit page
$pagObj.ResizeToFitContents()

Issues to look out for.

  • Credential issues:
    • Replace the line “Connect-NaController $FASName” with “Connect-NaController $FASName -Credential (Get-Credential)”
      • This will require the script to prompt for an Admins password of the filer.
  • Filer connecting issues:
    • Get the following error “The term ‘Connect-NaController’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.”
      • Make sure you import the OnTap module by running “Import-Module DataOnTap”

 

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s