Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Compare two locations, report on differences

$
0
0

I’m sure there’s a much more elegant way to do this, but this code will work for you:

$path = “C:\temp\TF.iQmetrix.CheckinPolicies.txt”
$patterns = @(“test”, “is”)

# Get all of the lines contains one or more patterns and loop through them.
$linesContainingPattern = (Select-String -Pattern $patterns -Path $path)
$fileNames = [string[]]@()	# Initialize empty string array to hold file names.
foreach ($line in $lines)
{
	# If we can find the FileName in this line.
	$match = [regex]::Match($line, “^(?<FileName>.*?):(?!\\)”) # Regex grabs all text from the start of the line until the first colon not followed by a backslash.
	if ($match.Success)
	{
		# Get the FileName out of the line and add it to our array of file names.
		$fileName = $match.Groups['FileName'].Value
		$fileNames += $fileName
	}
}

$fileNames

Viewing all articles
Browse latest Browse all 13067

Trending Articles