none
Need help with a powershell script RRS feed

  • Question

  • Hello friends,

    I have a program that creates the xml output file as below

    <?xml version="1.0" encoding="UTF-8"?>
    <DvMCLIResult version="8.5.1-00">
    <CommandResult command="GetStorageArray">
    <StorageArray objectID="ARRAY.R800.57457" name="SU55CYBSVSPG02" 
    <Pool objectID="JOURNALPOOL.R800.57457.5.14" name="ANET" 
    <PoolTier objectID="JOURNALPOOLTIER.R800.57457.5.14.0" tierID="0" 
    <PoolTier objectID="JOURNALPOOLTIER.R800.57457.5.14.1" tierID="1" 
    </Pool>
    <Pool objectID="JOURNALPOOL.R800.57457.5.21" name="Virtual" 
    <PoolTier objectID="JOURNALPOOLTIER.R800.57457.5.21.0" tierID="0" 
    <PoolTier objectID="JOURNALPOOLTIER.R800.57457.5.21.1" tierID="1" 
    </Pool>
    </StorageArray>
    </CommandResult>
    </DvMCLIResult>

    How Do I extract the output as follows:

    #<Storage Array>

    #(for Pool 1)
    StorageArray.Name Pool.ObjectID PoolTier.objectID #(For PoolTier 1)
    StorageArray.Name Pool.ObjectID PoolTier.objectID #(For PoolTier 2)

    #(for Pool 2)
    StorageArray.Name Pool.ObjectID PoolTier.objectID #(For PoolTier 1)
    StorageArray.Name Pool.ObjectID PoolTier.objectID #(For PoolTier 2)

    My Script is as follows:
    ========================
    Remove-Item –path F:\Manu\output.xml
    $command = 'HiCommandCLI GetStorageArray subtarget=Pool poolsubinfo=pooltier model=R800 serialnum=57434 -f xml -o F:\Manu\output.xml'
    iex $command

    [xml]$file= Get-Content -Path F:\Manu\output.xml

    foreach( $StorageArray in $file.DvMCLIResult.CommandResult.StorageArray)
    {
        Write-Host $StorageArray.name
        foreach( $Pool in $file.DvMCLIResult.CommandResult.StorageArray.Pool)
        {
            
            foreach( $PoolTier in $file.DvMCLIResult.CommandResult.StorageArray.Pool.PoolTier)
            {
            write-Host $file.DvMCLIResult.CommandResult.StorageArray.name $PoolTier.objectID $PoolTier.tierID $PoolTier.capacityInKB $PoolTier.freeCapacityInKB $PoolTier.usageRate $Pooltier.raidLevel $PoolTier.rpm
            }
            
        }
    }

    However, it outputs everything(pooltier) twice while I need details(pooltier) per 'Pool'

    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.1 1 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.1 1 
          
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.1 1 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.1 1 

    Required Output:
    ================

    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.14.1 1 

    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.0 0 
    SU55CYBSVSPG01 JOURNALPOOLTIER.R800.57434.5.21.1 1 

    Im not very well used to the powershell, so any help would be appreciated.

    • Moved by Bill_Stewart Thursday, January 25, 2018 10:07 PM Unanswerable drive-by question
    Tuesday, November 7, 2017 12:37 AM

All replies

  • $xml = Get=Content yourfile.xml

    Unfortunately the file you posted is not legal XML. You will have to fix it.


    \_(ツ)_/

    Tuesday, November 7, 2017 1:24 AM