1

I've an array with values as follow - $VolErrChk[0] has :

 VOLUME #2
I:
\Device\HarddiskVolume8
\\?\Volume{3559b156-d159-11e4-80c1-0050569cf1fd}
5117 MB.
0x000000304f65e304.
\\.\Volume{3559b156-d159-11e4-80c1-0050569cf1fd}
>      **** WARNING: DATA NOT AVAILABLE [0x00000100] ****

$VolErrChk[1] has :

     VOLUME #4
B:
\Device\HarddiskVolume20
\\?\Volume{3bf4ee0a-d050-11e4-80be-0050569cf1fd}
81917 MB.
0x000000304f65e304.
UNKNOWN.
>      **** WARNING: DATA NOT AVAILABLE [0x00000100] ****

I'm doing as follow -

 foreach ($disk in $VolErrChk)
    {
    $disk = ($VolErrChk-split "`n" | where {$_ -like "*?\Volume{*"})
    "type=ERROR;disk=$disk;"
    }

Can I get this output from 2 array values -

type=ERROR;disk=\\?\Volume{3559b156-d159-11e4-80c1-0050569cf1fd}
type=ERROR;disk=\\?\Volume{3bf4ee0a-d050-11e4-80be-0050569cf1fd}

2 Answers 2

2

You were close you just needed to split $disk and not $VolErrChk, and then pipe the output it into a foreach cmdlet (%) to output a volume on each line.

foreach ($disk in $VolErrChk){
    $disk -split "`n" | where {$_ -match "\\\\\?\\Volume{*" } | %{ "type=ERROR;disk=$_;" } 
}
Sign up to request clarification or add additional context in comments.

Comments

1

You don't have to split the string, you can just use a to capture the volume:

foreach ($disk in $VolErrChk)
{
    $disk = [regex]::Match($disk, '([\\]{2}\?\\Volume{[^}]+})').Groups[0].Value
    "type=ERROR;disk=$disk;"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.