Skip to content

PowerShell remove quotation marks from a text file

This article will show you how to remove quotation marks from a text file with PowerShell. Let’s find out why you need to remove quotation marks from a text file.

Information

Starting the new year, the finance team has a new application. Fantastic for the users that are going to work with the new system. The old system was a bit outdated, and the new application is looking good with a lot of new options. They need to import a text file in the new finance application. That file contains all the user’s names. The team at finance is getting an error after uploading the text file. Let’s see how we can help the finance team out.

Analyze the text file

After investigating the issue, it became clear. The problem is that the list got quotation marks in front and at the end of each name. We need to remove the quotation marks from the text file. Now comes the tricky part. If it was a list of 10 names, we could delete the quotation marks from a text file by hand, but it’s not. The list in the text file contains more than 10.000 entries.

Remove quotation marks with PowerShell

How are we going to help the finance team as they need to start using the application? The answer is PowerShell.

Before removing quotation marks with PowerShell

After opening the text file, we can see the quotation marks. It’s good to know that you can have names with a special character. See the highlighted names.

PowerShell remove quotation marks from text file analyze

Copy the file UsersBefore.txt to C:\Temp\. It should look like C:\Temp\UsersBefore.txt.

PowerShell remove quotation marks from text file path

Run PowerShell as Administrator against the text file with the following command. Make use of -Encoding UTF8 to keep the special characters.

PS C:\> (Get-Content "C:\Temp\UsersBefore.txt" -Encoding UTF8) | ForEach-Object {$_ -replace '"',''} | Out-File "C:\Temp\UsersAfter.txt" -Encoding UTF8

After removing quotation marks with PowerShell

A new text file is generated in the directory C:\Temp\ with the name UsersAfter.txt. Let’s open the created text file and see how it looks.

PowerShell remove quotation marks from text file result

It looks great without the quotation marks.

Keep reading: Export a list of mailboxes to text in Exchange »

Thoughts

PowerShell is excellent as you can do a lot with it. One more benefit is that you have PowerShell running on every Windows machine. Insert the command in PowerShell and run it. With a single command using PowerShell, we were able to remove the quotation marks.

Did you enjoy this article? You may also like Set automatic replies with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has One Comment

  1. Great article. It helped me a lot. I’m a senior citizen and always open to learning! Keep educating us Ali.

Leave a Reply

Your email address will not be published. Required fields are marked *