-3

can we just get results as

edf560af-db87-11e3-80d2-806e6f6e6963
faadf429-db69-11e3-919f-e0db55bf0b1b

Tried

(Get-WmiObject Win32_Volume |select  deviceid) -replace '\D'
# removes all except numbers

here is the cmd

Get-WmiObject Win32_Volume |select  deviceid

deviceid                                                                                                                                                                               
--------                                                                                                                                                                               
\\?\Volume{edf560af-db87-11e3-80d2-806e6f6e6963}\                                                                                                                                      
\\?\Volume{faadf429-db69-11e3-919f-e0db55bf0b1b}\                                                                                                                                      
\\?\Volume{faadf42d-db69-11e3-919f-e0db55bf0b1b}\                                                                                                                                      
\\?\Volume{faadf433-db69-11e3-919f-e0db55bf0b1b}\                                                                                                                                      
\\?\Volume{faadf439-db69-11e3-919f-e0db55bf0b1b}\                                                                                                                                      
\\?\Volume{edf560b0-db87-11e3-80d2-806e6f6e6963}\                                                                                                                                      
\\?\Volume{edf560b1-db87-11e3-80d2-806e6f6e6963}\                                                                                                                                      
\\?\Volume{edf560b5-db87-11e3-80d2-806e6f6e6963}\  
Matt
  • 45,022
  • 8
  • 78
  • 119

3 Answers3

0

Try this regex:

(?<=(Volume{))([\s\S]| |w\[0-9]| )+?(?=(}))
or simpler
(?<=Volume{).+(?=})

https://regex101.com/r/MHnxxh/4 or https://regex101.com/r/MHnxxh/5

0

Even a variant of your try can't work because it would also include the e in volume:

PS> (Get-WmiObject Win32_Volume |select  -expand deviceid) -replace '[^0-9a-f]'
ed0addcdf000000000000100000000000
ed0addcdf000000000000501f00000000
e775fc6ae9c7511e7b58e10604b928269
e2367fe0e45e311e6b548806e6f6e6963

Here another working solution using lookarounds:

Get-WmiObject Win32_Volume | Select-String '(?<=\{)[0-9a-f\-]+(?=\})' | ForEach-Object {$_.matches.value}
0

It appears that you want to capture only the hex digits between the LEFT CURLY BRACKET and the RIGHT CURLY BRACKET.

PS C:\src\t> cat .\dsm.ps1
Get-CimInstance CIM_StorageVolume |
    Select-Object DeviceID |
    ForEach-Object { $_ -match ".*{([-0-9a-fA-F]*)}.*" } |
    ForEach-Object { $matches[1] -replace '-' }

The output is:

PS C:\src\t> .\dsm.ps1
04ec358ff8bc11e3bac6806e6f6e6963
04ec3590f8bc11e3bac6806e6f6e6963
2bd2c32a00000000000090b4e8000000
c0adb44bbbcc11e5b3e7806e6f6e6963
lit
  • 14,456
  • 10
  • 65
  • 119