PowerShell Return Everything After The Last \ In A String
I’ve been playing around splitting out strings in PowerShell tonight and loving how much easier it is compared to T-SQL (https://sqlnotesfromtheunderground.wordpress.com/2013/09/28/t-sql-return-everything-after-the-last-in-a-string/).
Lets look at the same string as the T-SQL and see how to parse it:
## String $path = "SQLSERVER:\SQL\WT-FEW\DEFAULT\Databases\ReportServer" ## split the string into an array every "\" $breakout = $path.split("\") ## return the last element of the array write-host $breakout[-1] -ForegroundColor Green
Very quick and easy!