In my previous post I presented a script which makes it much faster to add many zones to a Cisco MDS switch with the use of the “single initiator – single target” principle. lately I have been working with some Brocade SAN switches which we will use in the future too. Because of this, I decided to copy my script, edit the script so you have the same feature now for adding zones quickly to the Brocade Fabric OS with the same procedure.
Powershell script
First let’s show this powershell script. After that, I will explain the differences between the powershell script of my previous post, where we used the same procedure for adding zones to Cisco MDS switches.
#Define the current script directory
$Current = split-path -parent $MyInvocation.MyCommand.Definition
$ScriptPath = "$($Current)\"
#Check whether aliasses.csv exists
$Initiators = "$($ScriptPath)initiators.txt"
$Targets = "$($ScriptPath)targets.txt"
$FileInitExists = Test-Path $Initiators
$FileTargetExists = Test-Path $Targets
#We need to use the quotation inside the commands later for Fabric OS
$q = [char]34
if ($FileInitExists -eq $false){
"Initiators.txt does not exist. Create it and place the initiator aliasses, one per line"
exit}
else {
if ($FileTargetExists -eq $false){
"Targets.txt does not exist. Create it and place the target aliasses, one per line"
exit}
}
#Create the zone config file
$ZonesFile = "BrocadeSwitch_New_Zones.txt"
New-Item $ZonesFile -ItemType file -Force
#create the loops and generate the zone commands in the output file
$Init_file = Import-Csv $Initiators
$Target_file = Import-Csv $Targets
foreach ($row_i.initiators in $Init_File){
foreach ($row_t.targets in $Target_File){
Add-Content $ZonesFile "zonecreate $($q)Z_$($row_i.initiators)_$($row_t.targets)$($q), $($q)$($row_i.initiators);$($row_t.targets)$($q)"
}
}
Write-Host "Ready! Create the aliasses from the Fabric OS GUI before pasting the output into the FOS SSH session and do not forget the cfgsave"
When using the Brocade Fabric OS, we do not make use of different VSAN’s, so the prompting for a specific VSAN is not necessary. Besides this, the command “zonecreate”, which I will generate the output for, needs to make use of double quotations, so I specified the double quotations with the following powershell command:
$q = [char]34
Now I can easily use the $q variable to specify the double quotation.
Initiator and target files
When you save the script in a folder, be sure to create the following files on that same location:
- Initiators.txt
- Targets.txt
Inside the Initiators.txt file, you will summarize all the initiator aliasses you want to zone to the targets. These will represent the hosts that are connected to the Brocade Fabric. In the example, we will use different VMware vSphere hosts as initiators.
initiators ESX01 ESX02 ESX03 ESX04
Note: Make sure the header called “initiators” is on top of the column
Inside the Targets.txt file, you will summarize all the targets that you want to zone to the initiators. These will represent the storage array ports that are connected to the Brocade SAN. In the example, we added a VNX5300 to the Brocade SAN.
targets VNX5300-SPA0 VNX5300-SPB1
Note: Make sure the header called “targets” is on top of the column
Commands output
When the text files are properly filled in, you can run the script. The script will now generate a file called “BrocadeSwitch_New_Zones.txt” which will consist of the following output:
zonecreate "Z_ESX01_VNX5300_SPA0", "ESX01;VNX5300_SPA0" zonecreate "Z_ESX01_VNX5300_SPB1", "ESX01;VNX5300_SPB1" zonecreate "Z_ESX02_VNX5300_SPA0", "ESX02;VNX5300_SPA0" zonecreate "Z_ESX02_VNX5300_SPB1", "ESX02;VNX5300_SPB1" zonecreate "Z_ESX03_VNX5300_SPA0", "ESX03;VNX5300_SPA0" zonecreate "Z_ESX03_VNX5300_SPB1", "ESX03;VNX5300_SPB1" zonecreate "Z_ESX04_VNX5300_SPA0", "ESX04;VNX5300_SPA0" zonecreate "Z_ESX04_VNX5300_SPB1", "ESX04;VNX5300_SPB1"
You can now simply select all the text inside this file and copy paste it into an SSH session to the Brocade FOS. When you do not see any errors arising, please do a “cfgsave” before opening the Fabric OS GUI. Now you only need to add the created zones to the active zoneset and you are done! Just like in my previous post for Cisco MDS switches, this script can save you some time when adding many zones to a configuration.
I tested the script on Fabric OS version 7.0.1, but I am not sure which older versions would maybe not support the exact same command.


