Why does the string for the -split parameter require two backslashes while the string for the -join parameter requires only one backslash? The backtick is the escape character in Powershell. What does a backslash preceding a character do for you?
$path = 'C:\folder\test\unit1\testing\results\report.txt'
$path -split '\\' -notlike '*test*' -join '\'
http://powershell.com/cs/blogs/tips/archive/2014/06/17/fun-with-path-names.aspx
-split
can take up to 3 parameters:<delimiter>
,<max-substrings>
,<options>
, so in Powershell <7.0,-split '\', -1, 'SimpleMatch'
means to split on `\`, return all matches (max-substrings of 0 or lower returns all in PS <7.0), and use SimpleMatch instead of the default RegexMatch. Reference: learn.microsoft.com/en-us/powershell/module/… – Koran