Match and select a part of required string from a string

Hello there!

Can someone help me how can I match and extract text from below:

\\SERVER1\D$\Folder7UPM2016\User1\UPM_Profile\AppData

Folder7UPM2016 is the UPM path where all user profiles are stored. I would like to extract “User1” from the path. Actually it can be any user name, here it’s User 1.

If the path is consistent, i.e. if all user folders are under \\SERVER1\D$\Folder7UPM2016\ just split it and get the 5th element:

PS E:\Temp> ('\\SERVER1\D$\Folder7UPM2016\User1\UPM_Profile\AppData' -split '\\')[5]
User1
2 Likes