Virtualization Articles and Resources

Script to Automate Registering HBAs with the Array.



     So the request was, how do I deploy a script that lets me deploy a set of between 5 and 10 Data Mining servers that each rip a copy of a database from the most recent hourly backup. I want each server to automatically create the clone from the last snapshot, then mount the LUN. I didn't want to write 10 scripts, and I didn't want to troubleshoot problems with non-existant iGroups, or mislabeled WWPNs.

This script assumes;

     You have either have a wide open fabric or have already previously zoned your switches.

     You have used the Connect-naController to connect to your target device.

What this script does;

     It will find your hostname, and put into a var called $hostname

     It will use the array to find the WWPN from your servers WWNN.

     It will Look for that WWPN in the Igroups, and if one doesnt exist it will create one using your $hostname and set the var $igroupname to be the hostname

     If an iGroup already exists, it will populate the var $igroupname with that name

     This script will run on all HBAs found in the system

Error conditions;

     If No HBAs are found, or if the WWPNs are not found on the array, the array will error out and tell you in either case.

$hostname=(Get-WmiObject -Class Win32_ComputerSystem).name
Write-host "Your Computer hostname is "$hostname

# The following piece of code will look for your local HBAs WWNs.
$foundHBA=$false; $igroupname=$false
foreach ($FCHBA in get-nahostfcadapter)
{      Write-host "Found HBA "$FCHBA.model" with WWNN of "$FCHBA.NodeWWN
      $foundHBA = $true
      # Since the Host only knows is WWNN, we need the WWPN, so we use the array to look for it.
      # Once we detect that WWNN, we know its WWPN.
      foreach($arrayport in get-nafcpinitiator)
      { foreach ($connection in $arrayport.fcpconnectedinitiators)
            { if ($connection.NodeName -like $fchba.nodewwn)
                  { Write-host "Found this WWNN on Array. Relates to WWPN "$connection.portname
                   # We also look to see it that WWPN is already in an iGroup. if not we create one
                   if ($connection.initiatorgrouplist)
                        { $igroupname = $connection.initiatorgrouplist
                         write-host "iGroup for this is named "$igroupname
                        { write-host "This WWPN is not in an iGroup, creating one now"
                         new-naigroup $hostname fcp windows
                         add-naigroupinitiator $hostname $connection.portname
                         $igroupname = $hostname

if ($iGroupName) # This means I found an HBA and a Target device
{      #Replace Parent Flexvol name, we use hostname embedded in lun names too...

      #These are the LUNs
      #Set clone volume Names


      #Set the Snapshot Names, this example always gets the 1 hour only snapshot.

      # Set the Mount Point Locations, and delete directorys if they exist
      $drive1="U:\Logs" | del; $drive2="V:\Logs" | del
      new-navolclone $clonevol1 $parentvol1 -Spacereserve none -parentsnapshot $snapname1

      Add-nalunmap $Clonepath1 $igroupname; Add-nalunmap $Clonepath2 $igroupname
      wait-nahost -controllerlunpath $clonepath1 | mount-nahostvol -mountpoint $drive1
      #Attaching SQL DBs
      & sqlcmd -E -S $hostname -d master -i "c:\scripts\attach_sql.sql"
{      if ($foundHBA)
      {      Write-Host "I Was able to find an $HBA, but not able to detect that HBA on the Target Device."
            Write-Host "Please Check zoning and cabling to ensure that this host can see the target array."

      {      Write-host "I was not able to find and HBAs in this system."

Please Note:

All content posted on the NetApp Community is publicly searchable and viewable. Participation in the NetApp Community is voluntary.

In accordance with our Code of Conduct and Community Terms of Use, DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information (PII)
  • Copyrighted materials without the permission of the copyright owner

Continued non-compliance may result in NetApp Community account restrictions or termination.

All Community Forums