I what I want to do is that it reads out all the folders from F: \ Test folder and writes it to C: \ temp without which it removes all folders containing al or AL. In the view itself in power shell ISE then shows the right but when it writes so take it with them al and AL
You need to use the Replace() method on $list variable rather than assigning a parameter to it (-Replace). And because PowerShell isn’t case-sensitive, you only need to use it once:
Function GetFileNames([string]$path, [string]$outputFile) {
$list = Get-ChildItem F:\test
$list = $list.Replace("al","") # Will replace any variation of 'al' - 'aL', 'AL', etc.
$list | Select-Object Name | Out-File $outputFile
}
GetFileNames ".\" "C:\temp\test.txt"