7-Mode ASUP LUN-CONFIGURATION Parser

This might be one of the more pointless things I’ve done (since there are perfectly good parsing tools out there already), but I just wanted to simply parse a LUN-CONFIGURATION file from a 7-Mode ASUP into a nice, easy to read, CSV. As always, these simple things never turn out quite as straightforward as they look at first glance. Anyway, without further to do, here’s the script:

Param([Parameter(Mandatory=$True)][String]$LunConfigurationFile)
[System.Array]$LunConf = Get-Content $LunConfigurationFile
[System.Array]$LunCSV = @()
[Boolean]$JustStarted = $TRUE
$LunConf | Foreach {
  $_ = $_.Trim(" ","`t")
  If($_.Startswith("/vol/")){
    If($JustStarted){ $LunCsv += ("LUN Path,Volume,Qtree,LUN,Size(MB),ROM,Comment,Serial,Share,Space Reservation,Multiprotocol Type,iGroup,LUN ID,Occupied Size(MB),Creation Time,Alignment,Cluster Shared Volume Information,Space_alloc,report-physical-size")}
    else{ $LunCSV += ($LUNPath + "," + $Volume + "," + $Qtree + "," + $LUN + "," + [String]$SizeMB + "," + $ROM + "," + $Comment + "," + $Serial + "," + $Share + "," + $SpaceR + "," + $MPType + "," + $Igroup + "," + $LUNID + "," + [String]$OccupiedMB + "," + $Creation + "," + $Align + "," + $CSVi + "," + $SpAlloc + "," + $ReportPhys) }
    [String]$Comment = [String]$Serial = [String]$Share = [String]$SpaceR = [String]$MPType = [String]$Igroup = [String]$LUNID = [String]$Creation = [String]$Align = [String]$CSVi = [String]$SpAlloc = [String]$ReportPhys = ""
    $JustStarted           = $FALSE
    [String]$LUNPath       = $_.Split(" ")[0]
    [System.Array]$SplitLP = $LUNPath.Split("/")
    # [0](1)/vol[1](2)/VOL[2](3)/QTREE[3](4)/LUN[4](5)
    [Int]$SpCount          = $SplitLP.Count           
    [String]$Volume        = $SplitLP[2]       
    If($SpCount -ge 5){ [String]$Qtree = $SplitLP[3] } else { [String]$Qtree = "" }
    [String]$LUN           = $SplitLP[$SpCount - 1]          
    [Int32]$SizeMB         = ($_.Replace("(",")").Split(")")[1])/(1024*1024)
    [String]$ROM           = ($_.Replace("(",")").Split(")")[3]).Replace(",",";")
  }
  elseif($_.Startswith("Comment:")){
    $Comment = $_.Substring(9) }
  elseif($_.Startswith("Serial#:")){
    $Serial  = $_.Substring(9) }
  elseif($_.Startswith("Share:")){
    $Share   = $_.Substring(7) }
  elseif($_.Startswith("Space Reservation:")){
    $SpaceR  = $_.Substring(19) }
  elseif($_.Startswith("Multiprotocol Type:")){
    $MPType  = $_.Substring(20) }
  elseif($_.Startswith("Maps:")){
    [System.Array]$Maps = $_.Substring(6).Split(" ")
    [Int]$TotalMaps = $Maps.Count
    [Int]$MapCount  = 0
    [String]$Igroup = ""
    [String]$LUNID  = ""
    Foreach ($Map in $Maps){
      $Igroup += $Map.Split("=")[0]
      $LUNID  += $Map.Split("=")[1]            
      $MapCount ++
      If($MapCount -ne $TotalMaps){
        $Igroup += ";"
        $LUNID  += ";"                  
      }             
    } 
  }
  elseif($_.Startswith("Occupied Size:")){
    [Int32]$OccupiedMB = ($_.Replace("(",")").Split(")")[1])/(1024*1024) }
  elseif($_.Startswith("Creation Time:")){
    $Creation   = $_.Substring(15) }
  elseif($_.Startswith("Alignment:")){
    $Align      = $_.Substring(11) }
  elseif($_.Startswith("Cluster Shared Volume Information:")){
    $CSVi       = $_.Substring(35) }
  elseif($_.Startswith("Space_alloc:")){
    $SpAlloc    = $_.Substring(13) }
  elseif($_.Startswith("report-physical-size:")){
    $ReportPhys = $_.Substring(22) }
}
$LunCSV | Set-Content ($LunConfigurationFile + ".CSV")



Comments