Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell parsing question

$
0
0

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


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>