Hello,
it is not enough to call a file ".csv" to get a csv. A csv is a comma separated file consisting of datasets (rows) with various properties (columns).
Out-File cmdlet is simply generating a text file. For generating csv use Export-CSV. But this will only work with an array of objects as imput. You simply have an array of strings.
To get a single-property csv, you simply have to add "USERID" at the beginning of your array. Or you can create an object like this way:
Select-String -Path $TXTFile -Pattern 'CN=(.*?),' -AllMatches |
Select-Object -Expand Matches |
ForEach-Object { $_.Groups[1].Value } |
select @{L="UserID"; E={$_}} |
Export-CSV $CSVFile -noTypeInformation