For more details, please see ourCookie Policy.

Fibre Channel (SAN) Technical Documents

Capture fibre switch port errors and clear errors for SAN Health using powershell

by Anonymous on ‎10-31-2012 04:59 AM (1,836 Views)

We have decided to run SAN Health on our fabrics in scheduled intervals. As it is recommended to clear the errors on the switches few days before you run the SAN Health, I had look into scripting to clear the errors for all ports on all switches.

The method used here is to use the open source utitlity called plink.exe (command line putty, which can be downloaded from PuTTY Download Page) to remotely run the commands porterrshow and porterrclear on each ports of the switches. The first pass will capture the current port errors to a file, which is best viewed using better file editor like notepad++ to keep the formatting. The script uses the smtp server to send the result to the mail box of your choice

the attachement contains

  • powershell script (Brocade-switch-err-clear.ps1)
  • List of fibre switches (fibre-switches.txt)
  • Command files (brocade1.txt & brocade2.txt)

If you are going to implement it in your environment you may have to do the following changes to the files

on Brocade-switch-err-clear.ps1

     update the smtp mail server and the from and to mail address

on fibre-switches.txt

     update the correct IP address in your farm

on brocade2.txt

     I have included the 40 ports in this list as I only have maximum of 40 ports in my switches, if you have more than 40 ports on any switch in the list above then you have to update this with the maximum number of ports.

Also download and copy the plink.exe to the same directory before running the script.

If you are planning to schedule this script to windows scheduler, try to run the script under the schedule user login to cache the SSH keys for the first time.

on ‎10-31-2012 08:24 AM


Thanks for your suggestions.

I'm a bit sceptical about this approach. I had some escalations some years ago with Brocade where they stated that shell-less command invokes using ssh or plink are not supported. I'm not sure if this is still true but from a tech support point of view it has a big advantage (beside of CPU utilization): it will not appear in the CLI history. There are some nice things you can calculate if you know exactly when the counters were cleared and that won't be possible anymore using the plain supportsaves when the counters were cleared like in your example. Maybe we could get some feedback from Brocade here...

Beside of that, is there a special reason why portstatsclear is used to clear the counters? I think for your example "statsclear" should be sufficient (I like to have it in combination with slotstatsclear to also clear the internal counters). If you want to look at the 64bit-counters then in old FOS version you needed portstatsclear but I just tried it with a 5100 on v6.4.2a and there a statsclear resets the 64bit counters as well.

Cheers seb

on ‎11-02-2012 01:52 PM

Hi ramesh_babu,

I'm moving your discussion to the Data Center SAN Community so that you will get the most responses possible. This particular forum is for non-product related questions.

Thank you for participating in Brocade Communities!


Grace Chang

Global Community Manager

by Anonymous
on ‎11-05-2012 07:26 AM

Hi Sebastian,

Statsclear should be ok with the newer switches. the only reason i used it because we have some older switches on another fabric.

I am not sure about the support for the shell less command. May be some brocade feedback would be appreciated here like you said.

‎11-17-2017 01:27 PM - edited ‎11-17-2017 04:49 PM

So everything is working out as perfect as i want but i am getting a mail with an empty attachment, where i don't see my port errors and rather the date and the IP . could anybody please help me in solving the issue. i am sure that i am missing a small one.

$SMTPSRV = "smtp"
$EmailFrom = ""
$EmailTo =""
$logFile = "Brocade-Log-" + (Get-date -f dd ).tostring() + (Get-date -f MM ).tostring() + ((Get-Date).year).tostring() + ".txt"

(get-date) > $logFile

Get-Content C:\Users\xyzpa\Desktop\fibre-switches.txt | % { $_ >> $logFile ; & 'C:\Users\xyzpa\Desktop\putty.exe' -l admin -pw Sty34viR -m C:\Users\xyzpa\Desktop\brocade1.txt $_ >> $logFile}
#GET-Content .\Desktop\fibre-switches.txt | % { & '.\Desktop\putty.exe' -l admin -pw password -m .\brocade2.txt $_ }

$MyReport = "Cleared Fibre switch errors for all brocade switches"
Send-MailMessage -To $EmailTo -Subject "Brocade switch error clear." -From $EmailFrom -Body $MyReport -SmtpServer $SMTPSRV -Attachments $LogFile

output of the above script.

Friday, November 17, 2017 6:53:26 PM

Here is the files used in the script.

fibre-switches.txt :
brocade1.txt : porterrshow

I tried with full path as well.


i tried with the below way as well.


$EmailFrom = ""
$EmailTo =""
$logFile = "Brocade-Log-$((GET-DATE).ToString("ddMMyyyy")).txt"

(get-date) >> $logFile

Get-Content .\fibre-switches.txt | % { $_ >> $LogFile ; & 'C:\users\khvs087pa\desktop\plink.exe' -L admin -pw Sty34viR -m .\brocade1.txt $_ >> $LogFile}
#Get-Content .\fibre-switches.txt | % { $_ >> $logFile ; & '.\plink.exe' -l admin -pw Sty34viR -m .\brocade1.txt $_ >> $logFile}
#Get-Content .\Desktop\fibre-switches.txt | % { & '.\Desktop\putty.exe' -l admin -pw password -m .\brocade2.txt $_ }

$MyReport = "Cleared Fibre switch errors for all brocade switches"
Send-MailMessage -To $EmailTo -Subject "Brocade switch error clear." -From $EmailFrom -Body $MyReport -SmtpServer $SMTPSRV -Attachments $LogFile


but getting this error.


plink.exe : Error: Unrecognized flag ('-L').
At C:\Users\khvs087pa\Desktop\Brocade-switch-err-clear.ps1:8 char:58
+ Get-Content .\fibre-switches.txt | % { $_ >> $LogFile ; & 'C:\users\khvs087pa\d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error: Unrecognized flag ('-L').:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

For more information, try 'plink --help [flag name]' or 'plink --help | more'.