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}
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=$_;" }
}
You don't have to split the string, you can just use a regex to capture the volume:
foreach ($disk in $VolErrChk)
{
$disk = [regex]::Match($disk, '([\\]{2}\?\\Volume{[^}]+})').Groups[0].Value
"type=ERROR;disk=$disk;"
}
User contributions licensed under CC BY-SA 3.0