Export Users Attributes to CSV. Remove special char from the exported CSV

The script below gets all the users from a specific OU and export users' samaccount name and SID. Then removed the character " from the csv file.

$Outputfile = ForEach-Object{
Get-ADUser -Filter * -SearchBase "OU=TestDomainUsers,DC=test,DC=local" | select SamAccountName, SID
$Outputfile | Export-Csv -Path "c:\UserSIDs.csv"
#Remove " character from the output file
(Get-Content C:\UserSIDs.csv) | ForEach-Object { $_ -replace '"' } > C:\UserSIDs.csv
  • Hits: 412