How to extract text from field?

I need to extract the resource group name (in blue) from this field to use in a variable. What is the easiest way to do this? The subscription number might change but will always be the same length.

Id : /subscriptions/f63f7a9e-2700-4c86-af00-67e86abb0000/resourcegroups/RG-025-311-WVD/providers/Microsoft.DesktopVirtualization/hostpools/025-113-Pool-P

If it’s always going to be that path, you could do it in a couple of ways. First, you can split at the slash and grab the appropriate element.

$string = @'
Id : /subscriptions/f63f7a9e-2700-4c86-af00-67e86abb0000/resourcegroups/RG-025-311-WVD/providers/Microsoft.DesktopVirtualization/hostpools/025-113-Pool-P
'@

@($string -split '/')[4]

Output:

RG-025-311-WVD

Perhaps an easier to modify approach would be using regex. If the path changes just modify it.

$string = @'
Id : /subscriptions/f63f7a9e-2700-4c86-af00-67e86abb0000/resourcegroups/RG-025-311-WVD/providers/Microsoft.DesktopVirtualization/hostpools/025-113-Pool-P
'@

if($string -match 'resourcegroups\/(?<resourcegroup>.*)\/providers'){$matches.resourcegroup}

Output:

RG-025-311-WVD

I hope this helps.