Fun with Path Names

by Jun 17, 2014

You can use the -split operator to easily split a path in its components. The result is always an array.

Simply use comparison operators to exclude any part component you do not like, or rename some, then use -join to put the path back together.

This would exclude all subfolders in a path that contain the word "test":

$path = 'C:\folder\test\unit1\testing\results\report.txt'

$path -split '\\' -notlike '*test*' -join '\' 

Twitter This Tip! ReTweet this Tip!