Powershell, Sans, Excel and XML


Here is a function that uses the San Surfer command line tool to pull the World Wide Name and World Wide Port Names from a QLogic HBA. I needed a lot of help with this one, and I got it.
It uses PSExec to run SCLI.EXE on the remote server.
########
Function SanCLI($strComputer) {
If (Test-Path "\\$strComputer\C$\Program Files\SANsurferCLI\scli.exe") {
$rRow = $row
$psinfoOutput = c:\psTools\psexec.exe \\$strComputer -w "C:\Program Files\QLogic Corporation\SANsurferCLI" "C:\Program Files\QLogic Corporation\SANsurferCLI\scli.exe" -I ALL -X #$xml = [xml]($psinfoOutput | where{$_})
$a = $xml.QLogic.HBA[0].GeneralInfo
$b = $xml.QLogic.HBA[1].GeneralInfo
$ws1.Cells.Item($rRow,17) = $a.Model
$ws1.Cells.Item($rRow,18) = $a.WWNN
$ws1.Cells.Item($rRow,19) = $a.WWPN
$ws1.Cells.Item($rRow,20) = $a.DriverVersion
$ws1.Cells.Item($rRow,21) = $a.BIOSVersion
$ws1.Cells.Item($rRow,22) = $a.FirmwareVersion
$rRow++
$ws1.Cells.Item($rRow,17) = $b.Model
$ws1.Cells.Item($rRow,18) = $b.WWNN
$ws1.Cells.Item($rRow,19) = $b.WWPN
$ws1.Cells.Item($rRow,20) = $b.DriverVersion
$ws1.Cells.Item($rRow,21) = $b.BIOSVersion
$ws1.Cells.Item($rRow,22) = $b.FirmwareVersion
}
Else {
Copy-Item D:\QLogic\scli*.exe -destination \\$strComputer\C$\Temp
c:\psTools\psexec.exe \\$strComputer -w "C:\Temp" "C:\Temp\scli-1.7.3-37.windows.exe"
SanCLI($strComputer)
}
$row = $rRow
}

But, you say you don’t have QLogic HBA’s. How can I get this information?
You can use the utility from Microsoft called FCInfo.exe. (Fiber Channel Information, clever yes?)
It is available at this location:
http://www.microsoft.com/downloads/details.aspx?familyid=73d7b879-55b2-4629-8734-b0698096d3b1&displaylang=en
Since fcinfo isn’t officially supported in Windows 2008 you can download the tools for Windows 2008 from the vendor HBA website.
For Windows collection the command “scli” (Qlogic) or “hbacmd” (Emulex) is comparable to fcinfo.
Here is a function I wrote using FCInfo and psexec to poll a number of machines:
Function FCInfo ($strComputer) {
$xRow = $rRow
$PSpath = C:\PSTools
If (Test-Path "C:\PSTools\fcinfo.exe") {
$wwn = C:\PSToolspsexec.exe \\$strComputer $PSPath fcinfo.exe /details

$adapter = $wwn | Select-String -pattern "Adapter:" -allmatches -simplematch
$ws.Cells.Item($rRow,16) = $adapter[0]
$rRow++
$ws.Cells.Item($rRow,16) = $adapter[1]
$rRow = $rRow - 1
$node_wwn = $wwn | Select-String -pattern "node_wwn:" -allmatches -simplematch
$ws.Cells.Item($rRow,17) = $node_wwn[0]
$rRow++
$ws.Cells.Item($rRow,17) = $node_wwn[1]
$rRow = $rRow - 1
$port_wwn = $wwn | Select-String -pattern "port_wwn:" -allmatches -simplematch
$ws.Cells.Item($rRow,18) = $port_wwn[0]
$rRow++
$ws.Cells.Item($rRow,18) = $port_wwn[1]
}
$rRow = $xRow
}


Here is some info from Wikipedia on HBA’s and World Wide Names:
Today, the term host bus adapter (HBA) is most often used to refer to a Fibre Channel interface card.
There are two types of WWNs on a HBA; a node WWN (WWNN), which is shared by all ports on a host bus adapter, and a port WWN (WWPN), which is unique to each port.
Advertisements

One thought on “Powershell, Sans, Excel and XML

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