Hello,
I’m trying to extract certain content from the return of one of my scripts. The return value has a delimiter of ‘/’.
Here’s an example:
/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg
I’d like to pull the value after the last delimiter ‘/’.
Any idea on how to extract that content?
Thanks,
Frank
[pre]
$value = “/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg” -split “/”
$lastsplit = $value[$value.count -1]
[/pre]
heres one approach, if the number of / will always be the same, then you can reference it as $value[4]
Another method is using GetUpperBound:
$value = "/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg" -split "/"
$value[$value.GetUpperBound(0)]
# Get last string in array after splitting
$string = '/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg'
$string.Split('/')[-1]
All of them work great, but the I’m going to use:
[pre]
@{Expression={$_.Scope.Split(‘/’)[-1]};Label=“Scope”;width=100}
[/pre]
It was easier to add to my existing code than the others and returns exactly what I need.
I appreciate everyone’s help! Thx!