Powershell parsing question

Hi all,

I'm trying to parse the below data and write it into a CSV file. I need to gather all the bolded data and the script that I have allows me to get the first 16 items (which is  exactly what i need) however i'm missing one vital piece of information and that is the enclosure name (hilighted in bold and underlined). I'm not sure how i can add it. Any help would be appreciated and thanks in advanced. 

--Gaz  


HP BladeSystem Onboard Administrator
(C) Copyright 2006-2012 Hewlett-Packard Development Company, L.P.

INFWPSC04A [SCRIPT MODE]> show server names


Bay Server Name                   Serial Number   Status   Power   UID Partner
--- ----------------------------- --------------- -------- ------- --- -------
  1 304XUSE02                USEECB      OK       On      Off
  2 305XUSE02                USEECJ      OK       On      Off
  3 306XUSE02                USEECL      OK       On      Off
  4 308XWRL11                USEECD      OK       On      Off
  5 304XUSE03                USEECP      OK       On      Off
  6 305XUSE03                USEECH      OK       On      Off
  7 306XUSE03                USEECN      OK       On      Off
  8 308XWRL12                USEECA      OK       On      Off
  9 304XUSE04                USEECK      OK       On      Off
 10 305XUSE04                USEECM      OK       On      Off
 11 306XUSE04                USEECF      OK       On      Off
 12 100XHLD07                USEECR      OK       On      Off
 13 304XUSE05                USEECE      OK       On      Off
 14 305XUSE05                USEECS      OK       On      Off
 15 306XUSE05                USEEC9      OK       On      Off
 16 100XHLD08                USEECC      OK       On      Off
Totals: 16 server blades installed, 16 powered on.

INFWPSC04A [SCRIPT MODE]>

show server names


HP BladeSystem Onboard Administrator
(C) Copyright 2006-2011 Hewlett-Packard Development Company, L.P.

INFWPSC02A [SCRIPT MODE]> show topology


Rack Topology (top-down)


Rack UUID: ALL5
Rack Name:11


         Enclosure Name           Status  Local   IP Address         UUID
-------------------------------- -------- ----- --------------- --------------
INFWPSC02                     OK       Yes   10.1.1.1         E121ALL5 

INFWPSC02A [SCRIPT MODE]>
show topology

PowerShell Script

----------------------------------------------------------------------------------------------

$vara = get-childitem -name "D:\ServerInfo\"

$varb = foreach ($q in $vara) {gc "D:\ServerInfo\$q"}

#loop through the text and assign the result to commaSeparatedInfo
$commaSeparatedInfo = foreach($line in $varb){
    #if the line starts with a number or any number of spaces followed by a number, process it, otherwise we'll ignore it
    if($line -match "^\s*\d"){
        #remove the leading spaces if there are any
        $line = $line -replace "^\s*"
        #replace any remaining spaces between the text with a comma and emit the line (should have csv at this point)
        $line -replace "\s+",","
    }
}
#create the header to parse the csv as an array
$header = "Bay","ServerName","SerialNumber","Status","Power","UID","Partner"
#convert the csv into objects with convertfrom-csv using the header
$parsedInfo = $commaSeparatedInfo|convertfrom-csv -Header $header
#select out just the fields that you want.
$EncData = $parsedInfo|select Bay,ServerName,SerialNumber

February 3rd, 2014 1:27pm

Is all of that table data in a single text file? It's a pretty annoying format to have to parse; it's not delimited, and doesn't even appear to be properly fixed-width either (the data doesn't line up with the headers in a fixed-width font, unless that's just a problem with how the data was pasted to the forums.)

If it's absolutely necessary to parse this format, you can probably make it work, but the first thing I'd do is check that "HP BladeSystem Onboard Administrator" tool to see if it can be made to display or save its output in another format.  Many of these types of tools support creating CSV or XML data directly, and that would make your life a lot easier.

Free Windows Admin Tool Kit Click here and download it now
February 3rd, 2014 3:17pm

Is all of that table data in a single text file? It's a pretty annoying format to have to parse; it's not delimited, and doesn't even appear to be properly fixed-width either (the data doesn't line up with the headers in a fixed-width font, unless that's just a problem with how the data was pasted to the forums.)

If it's absolutely necessary to parse this format, you can probably make it work, but the first thing I'd do is check that "HP BladeSystem Onboard Administrator" tool to see if it can be made to display or save its output in another format.  Many of these types of tools support creating CSV or XML data directly, and that would make your life a lot easier.

February 3rd, 2014 11:16pm

Hi,

As far as I can see that you used two different commands(one is show server names, another is show topology) displayed two types information, and then you want to save both the result in one CSV file. And in your script, you are using regex to get those information. What is the result when you run the script for each result?

As David said, please check out whether the tool you used have function to save result in CSV format.

Regards,

Yan Li

Free Windows Admin Tool Kit Click here and download it now
February 6th, 2014 12:53am

Gazzamon,

Here's one way to do it.

$ServerInfo = Get-Content $FileName
ForEach ( $i in 0..($ServerInfo.Length - 1) )
    {
    If ( $ServerInfo[$i] -like "*Enclosure Name*" )
        {
        $EnclosureName = $ServerInfo[$i+2].Substring(0,20).Trim(" ")
        }
    }

February 6th, 2014 3:00pm

Sorry folks for not getting back to you all sooner. I wanted to thank you all for your help.

-Gaz

Free Windows Admin Tool Kit Click here and download it now
February 18th, 2014 3:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics