I have a command line utility that queries the HBA's on a server and
return all sorts of usefull information.
What I am looking for is the World Wide Name of each port.
The Output looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<QLogic>
<AppName>SANsurfer FC CLI</AppName>
<AppVersion>v1.06.14 Build 25</AppVersion>
<HBA>
<GeneralInfo Number="0"
Model="QLA2312"
WWNN="##-##-##-##-##-##-##-##"
WWPN="##-##-##-##-##-##-##-##"
</HBA>
<HBA>
<GeneralInfo Number="1"
Model="QLA2312"
WWNN="##-##-##-##-##-##-##-##"
WWPN="##-##-##-##-##-##-##-##"
</HBA>
I get this info by running this:
$psinfoOutput = c:\psTools\psexec.exe \\$strComputer -w "C:\Program
Files\SANsurferCLI" "C:\Program Files\SANsurferCLI\scli.exe" -I ALL -
X
So, I need to parse $psinfoOutput for my data.
I tried this:
$xd.load($psinfoOutput)
$nodelist = $xd.selectnodes("//*[@Name=SANsurfer FC CLI']\HBA")
foreach ($testCaseNode in $nodelist) {
$WWNN = $testCaseNode.getAttribute("WWNN")
$WWPN = $testCaseNode.getAttribute("WWPN")
$ws.Cells.Item($rRow,16) = $WWNN
$ws.Cells.Item($rRow,17) = $WWPN
But it's not working. I think I need to get down intop the
GeneralInfo
level, But I don't know how.
TIA,
OLDDOG
If you run this in session or with a breakpoint what does the selectnodes()
method return?
"OldDog" wrote:
> .
>
Hi,
I won't "Load":
$xd.load($psinfoOutput)
You cannot call a method on a null-valued expression.
At line:1 char:9
+ $xd.load <<<< ($psinfoOutput)
+ CategoryInfo : InvalidOperation: (load:String) [],
RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Looks like I need to pull the data in another way. I can creat a
temporary xml file.
But when I do that, I can get any further down the tree than:
GeneralInfo
-----------
GeneralInfo
GeneralInfo
PS C:\temp> cd scripts:
PS Scripts:\> $xml=[xml](Get-Content \\MYTESTSERVER\c$\temp
\output.xml)
PS Scripts:\> $a = $xml.SelectNodes("//*[@Name='QLogic']/HBA/
GeneralInfo")
PS Scripts:\> $a | select Number,Model,WWNN,WWPN
PS Scripts:\> $a
PS Scripts:\>
PS Scripts:\> $a.number
PS Scripts:\> $xml
xml QLogic
--- ------
version="1.0" encoding="ISO-8859-1" QLogic
If I do this:
$xml.QLogic
I get this:
AppName : SANsurfer FC CLI
AppVersion : v1.06.14 Build 25
HBA : {HBA, HBA}
Status : 0
Reboot : 0
And this:
$xml.QLogic.HBA
Gets this
GeneralInfo
-----------
GeneralInfo
GeneralInfo
If i try this
$xml.QLogic.HBA.GeneralInfo
I get nothing
$xml = [xml]$psinfoOutput
As far as the actual XML, I don't know how much you edited what you actually
are getting back but the sample you posted is not well formed. The
<GeneralInfo> tag is not closed.
Assuming that is just your editing, then your final example
$xml.QLogic.HBA.GeneralInfo still won't return anything because there are two
HBA tags so you'd need to index into one:
$xml.QLogic.HBA[0].GeneralInfo
Running with a fixed up version of your example the following sample code
returned expected data:
$xml.SelectNodes('//GeneralInfo') | %{ $_.WWNN; $_.WWPN }
Hope that helps,
paul
"OldDog" wrote:
> .
>
PS Scripts:\> $xml = [xml]$psinfoOutput
Cannot convert value "System.Object[]" to type
"System.Xml.XmlDocument". Error: "Unexpected XML dec
laration. The XML declaration must be the first node in the document,
and no white space characters
are allowed to appear before it. Line 2, position 3."
At line:1 char:26
+ $xml = [xml]$psinfoOutput <<<<
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Here is my full XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<QLogic>
<AppName>SANsurfer FC CLI</AppName>
<AppVersion>v1.06.14 Build 25</AppVersion>
<HBA>
<GeneralInfo Number="0"
Model="QLA2312"
WWNN="##-##-##-##-##-##-##-##"
WWPN="##-##-##-##-##-##-##-##"
PortID="61-4E-13"
SerialNumber="N40090"
DriverVersion="9.1.0.13 (w32 IP)"
BIOSVersion="1.45"
FirmwareVersion="3.03.18"
TargetCount="1"
PCIBus="1"
PCIDevice="3"
ActualConnectionMode="Point To Point"
ActualDataRate="2 Gbps"
PortType="NPort"
Status="Online" />
</HBA>
<HBA>
<GeneralInfo Number="1"
Model="QLA2312"
WWNN="##-##-##-##-##-##-##-##"
WWPN="##-##-##-##-##-##-##-##"
PortID="62-4E-13"
SerialNumber="N40346"
DriverVersion="9.1.0.13 (w32 IP)"
BIOSVersion="1.45"
FirmwareVersion="3.03.18"
TargetCount="1"
PCIBus="1"
PCIDevice="35"
ActualConnectionMode="Point To Point"
ActualDataRate="2 Gbps"
PortType="NPort"
Status="Online" />
</HBA>
<Status> 0 </Status>
<Reboot> 0 </Reboot>
</QLogic>
$xml = [xml]($psinfoOutput | where{$_})
That should strip out the leading blank line and allow the XML to load.
Paul
And we have a Winner! What do we have for our lucky constestant
Johnny?
How about a working Function?
Here you go!
#<---- Begin Function
Function SanCLI($strComputer) {
If (Test-Path "\\$strComputer\C$\Program Files\SANsurferCLI
\scli.exe")
{
$xRow = $rRow
$psinfoOutput = c:\psTools\psexec.exe \\$strComputer -w "C:\Program
Files\SANsurferCLI" "C:\Program Files\SANsurferCLI\scli.exe" -I ALL -
X
$xml = [xml]($psinfoOutput | where{$_})
$a = $xml.QLogic.HBA[0].GeneralInfo
$b = $xml.QLogic.HBA[1].GeneralInfo
$ws.Cells.Item($rRow,16) = $a.WWNN
$ws.Cells.Item($rRow,17) = $a.WWPN
$rRow++
$ws.Cells.Item($rRow,16) = $b.WWNN
$ws.Cells.Item($rRow,17) = $b.WWPN
}
$rRow = $xRow
}
#<---- End Function
Paul
"OldDog" wrote:
> And we have a Winner! What do we have for our lucky constestant
> Johnny?
>
> How about a working Function?
>
>
> Here you go!
>
> #<---- Begin Function
>
> Function SanCLI($strComputer) {
> If (Test-Path "\\$strComputer\C$\Program Files\SANsurferCLI
> \scli.exe")
> {
> $xRow = $rRow
> $psinfoOutput = c:\psTools\psexec.exe \\$strComputer -w "C:\Program
> Files\SANsurferCLI" "C:\Program Files\SANsurferCLI\scli.exe" -I ALL -
> X
> $xml = [xml]($psinfoOutput | where{$_})
> $a = $xml.QLogic.HBA[0].GeneralInfo
> $b = $xml.QLogic.HBA[1].GeneralInfo
> $ws.Cells.Item($rRow,16) = $a.WWNN
> $ws.Cells.Item($rRow,17) = $a.WWPN
> $rRow++
> $ws.Cells.Item($rRow,16) = $b.WWNN
> $ws.Cells.Item($rRow,17) = $b.WWPN
> }
> $rRow = $xRow
>
> }
>
> #<---- End Function
>
> .
>
Thanks for all your help. BTW: can you explain this bit?
where{$_})
I am not sure what or how that works and I don't belive I have seen it
before.
OldDog
It *won't* filter out whitespace, so if there had been even a single space
or tab on that first line it wouldn't have worked.
#This works
"","foo" | where {$_}
#this doesn't
" ","foo" | where {$_}
Paul
"OldDog" wrote:
> .
>
Cool, thanks for that. I have learned another new trick. Not bad for
an OldDog!