How to Convert Unicode to ASCII using PowerShell

When working with text processing, data migration, or system integration in PowerShell, encoding challenges often arise. Unicode is now the default for most systems and applications.

However, situations may require conversion to ASCII—for instance, when supporting legacy applications, cleaning data, or prepping information for APIs that cannot handle special characters.

In this tutorial, I will explain how to convert unicode to ASCII using PowerShell with examples.

Unicode vs. ASCII

Unicode is a universal character encoding standard. It supports characters for almost every language, as well as symbols, emojis, and technical glyphs. Data is usually represented with UTF-8 or UTF-16 encoding, which allows for billions of possible characters.

ASCII, on the other hand, is an older and much more limited standard—covering only 128 characters, which includes the English alphabet, numbers, and several control symbols.

Converting Unicode to ASCII in PowerShell ensures compatibility, but can result in data loss—special characters, diacritics, and symbols not present in ASCII become question marks or are stripped out entirely.

Ensure to use PowerShell 5.1 or PowerShell 7+.

You can check the PowerShell version using the below cmdlet.

$PSVersionTable.PSVersion

You may need to adjust the script execution policy:

Set-ExecutionPolicy RemoteSigned

One of the most important points: Always back up files before batch conversions, as data loss from unmatched characters is permanent.

Check out Convert HEIC to JPG using PowerShell

Method 1: Using .NET Encoding Classes

PowerShell leverages the .NET framework. You can use the System.Text.Encoding class to handle conversions and encoding changes.

  • Create a Unicode string:
$text = "Hello – World ©"
  • Convert to ASCII using .NET methods:
$text = "Hello – World ©"
$unicodeBytes = [System.Text.Encoding]::Unicode.GetBytes($text)
$asciiBytes = [System.Text.Encoding]::Convert([System.Text.Encoding]::Unicode, [System.Text.Encoding]::ASCII, $unicodeBytes)
$asciiText = [System.Text.Encoding]::ASCII.GetString($asciiBytes)
Write-Output $asciiText
  • Output: Hello ? World ?
  • The special en-dash and copyright sign are both replaced with ? as ASCII does not support them

You can see the exact output in the screenshot below:

Convert Unicode to ASCII using PowerShell

Pros and Cons:

  • Pros: Uses built-in .NET. Fast. Simple for pure conversion.
  • Cons: Unsupported Unicode characters become ?, which may hinder readability or corrupt intent.

Read Convert JSON to XML using PowerShell

Method 2: Removing Non-ASCII Characters with Regex

For strict scenarios demanding only printable ASCII, PowerShell’s -replace operator with regular expressions does the job.

  • Remove Non-ASCII:
    • Using hex range for standard ASCII (0x00 to 0x7F):
$text = "Data©2025✓ Powered"
$asciiText = $text -replace '[^\x00-\x7F]', ''
Write-Output $asciiText

Output: Data2025 Powered
Now, all special Unicode symbols are completely gone, not replaced by ?

Here is the exact output in the screenshot below:

powershell convert unicode to ascii
  • Alternate: Remove Non-ASCII with Unicode block:
$asciiText = $text -creplace '\P{IsBasicLatin}'
Write-Output $asciiText

This method removes every character outside standard ASCII (Latin block).

Use Cases:

  • Cleaning log files
  • Stripping user input for legacy systems
  • Preparation for storage in ASCII-only databases

Check out Convert Bytes to GB in PowerShell

Method 3: Mapping Unicode Characters to Closest ASCII

When meaning should be preserved, mapping specific symbols to descriptive ASCII substitutes is extremely helpful.

  • Define mapping:
$mappings = @{
  "©" = "(c)"
  "–" = "-"
  "✓" = "OK"
}
  • Replace in text:
$mappings = @{
  "©" = "(c)"
  "–" = "-"
  "✓" = "OK"
}
$text = "Company© – Verified✓"
foreach ($key in $mappings.Keys) {
  $text = $text.Replace($key, $mappings[$key])
}
Write-Output $text

Output: Company(c) - VerifiedOK

Here is the exact output in the screenshot below:

How to Convert Unicode to ASCII using PowerShell

Check out PowerShell Convert XML to Object

Method 4: Converting Files During Read/Write

If you need to convert entire files, utilize the encoding options in file reading and writing cmdlets.

  • Write to ASCII
$text = "Hello – World ©"
[System.IO.File]::WriteAllText("unicode.txt", $text, [System.Text.Encoding]::Unicode)
$content = Get-Content "unicode.txt"
[System.IO.File]::WriteAllText("ascii.txt", $content, [System.Text.Encoding]::ASCII)

Opening ascii.txt will reveal all unsupported characters replaced by ?

  • Using Out-File
Get-Content "unicode.txt" | Out-File "ascii_via_outfile.txt" -Encoding ASCII

This method is ideal for bulk conversions or automation scripts.

Check out Convert XML to CSV in PowerShell

Handling Special Cases and Data Loss

Unsupported Characters

Any Unicode code point outside of the ASCII range (like emojis, accented letters, and special symbols) will be lost or replaced. Diacritics (like é, ñ, å) do not survive the conversion—sometimes an alternative mapping is necessary for clarity.

When Not to Use ASCII Conversion

If working with non-English text (Hindi, Chinese, Arabic, etc.), converting to ASCII is likely to produce unreadable or corrupted data. Evaluate whether UTF-8 with normalization is more appropriate in such cases.

Check out PowerShell Convert Secure String to Plain Text

PowerShell Convert Unicode to ASCII Examples

Now, let me show you some examples.

  1. Cleaning API Input
$payload = $payload -replace '[^\x00-\x7F]', ''
  1. Sanitizing Log Files
Get-Content "log.txt" | ForEach-Object { $_ -replace '[^\x00-\x7F]', '' } | Set-Content "clean_log.txt"
  1. Database Text Preprocessing

Before loading large CSVs into a legacy system:

Import-Csv data.csv | ForEach-Object {
  $_.Name = $_.Name -replace '[^\x00-\x7F]', ''
  $_
} | Export-Csv clean_data.csv -NoTypeInformation

Best Practices for Unicode to ASCII Conversion

  • Always back up original data.
  • Test each approach with representative examples—especially if scripts run automatically.
  • Use mapping for symbols that have widely accepted ASCII equivalents.
  • Communicate limitations to stakeholders, especially about lost characters or data integrity changes.

Conclusion

PowerShell makes it easy to convert Unicode to ASCII using .NET encoding classes, file output parameters, regular expressions, or custom mappings. Each method serves different requirements—from rough cleaning to meaning-preserving normalization. Always consider the value and visibility of data loss for your specific use case and automate backups or testing before full migration.

Do let me know in the comments below if it helps.

You may also like:

Leave a Comment

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.