Powershell: Remove the last ‘/’ character in a string with multiple paths in it from each path

Question:

I’m looking to remove the final ‘/’ character from a string that contains multiple storage paths in it, what is the best way to go about this, I keep getting close but I still can’t quite get what I’m looking for, is a loop really the only way?

I’m currently getting errors like the following:

The desired final version of $Paths would be

Any help would be greatly appreciated, I think I may have a process issue as well as a coding issue…

Answer:

Use the .TrimEnd() method.

Source:

Powershell: Remove the last ‘/’ character in a string with multiple paths in it from each path by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply