You can simply use the GetExtension function from System.IO.Path :
foreach ($line in $lines) { $extn = [IO.Path]::GetExtension($line) if ($extn -eq ".xml" ) { } }
Demo:
PS > [IO.Path]::GetExtension('c:\dir\file.xml') .xml PS > [IO.Path]::GetExtension('c:\dir\file.xml') -eq '.xml' True PS > [IO.Path]::GetExtension('Test1.xml') # Also works with just file names .xml PS > [IO.Path]::GetExtension('Test1.xml') -eq '.xml' True PS >
source share