Read text after the last backslash
I want to read the text after the last backslash from my text file. I currently have:
$data=Get-Content "C:\temp\users.txt"
The users.txt file contains the path from the users home directories
\\myserver.home.com\users\user1.test
How can I select the user account name (user1.test) at the end of the line of text so that I can use it as a variable?
+3
source to share
4 answers
Since you are dealing with file paths, you can use GetFileName :
$data=Get-Content "C:\temp\users.txt"
$name=[System.IO.Path]::GetFileName($data)
+5
source to share