Maybe my reasoning is faulty, but I can\'t get this working.
Here\'s my regex: (Device\\s#\\d(\\n.*)*?(?=\\n\\s*Device\\s#|\\Z))
Try it: http://
While it doesn't exactly answer your question, I'll offer a slightly different approach:
($getdevice) -split '\s+(?=Device #\d)' | select -Skip 1
Just for fun,
$drives =
($getdevice) -split '\s+(?=Device #\d)' |
select -Skip 1 |
foreach { $Stringdata =
$_.replace(' : ','=') -replace 'Device #(\d)','Device = $1' -Replace 'Device is a (\w+)','DeviceIs = $1'
New-Object PSObject -Property $(ConvertFrom-StringData $Stringdata)
}
$drives | select Device,DeviceIs,'Total Size'
Device DeviceIs Total Size
------ -------- ----------
0 Hard drive 70007 MB
1 Hard drive 70007 MB
2 Hard drive 286102 MB
3 Hard drive 286102 MB