Recently, someone in the PowerShell development team asked me to convert the Base64 string to text in Powershell. I explained how to do this using various methods. In this tutorial, I will show you how to convert Base64 string to text in PowerShell with examples.
To convert a Base64 string to text in PowerShell, you can use the [System.Convert]::FromBase64String() method. This method decodes the Base64 string into a byte array, which can then be converted to a readable text string using [System.Text.Encoding]::UTF8.GetString(). For instance, given a Base64 string $base64String = "SGVsbG8gV29ybGQh", you can decode it with:
$bytes = [System.Convert]::FromBase64String($base64String)
$text = [System.Text.Encoding]::UTF8.GetString($bytes)
Write-Output $textThis will output “Hello World!”.
What Are Base64 Encoding in PowerShell?
Base64 encoding is a method for encoding binary data into an ASCII string format by translating it into a radix-64 representation. Each Base64 digit represents exactly 6 bits of data. This encoding is commonly used in various applications, including email via MIME, storing complex data in XML or JSON, and embedding image data within HTML or CSS.
Convert Base64 String to Text in PowerShell
Now, let me show you how to convert Base64 string to text in PowerShell using various methods with examples.
Method 1: Using [System.Convert]::FromBase64String()
The best method to decode a Base64 string in PowerShell is by using the [System.Convert]::FromBase64String() method. This method converts the Base64 encoded string back to a byte array, which can then be converted to a readable text string.
Here is an example.
# Base64 encoded string
$base64String = "SGVsbG8gV29ybGQh"
# Decode Base64 string to byte array
$bytes = [System.Convert]::FromBase64String($base64String)
# Convert byte array to text
$text = [System.Text.Encoding]::UTF8.GetString($bytes)
# Output the text
Write-Output $textIn this example, the Base64 string SGVsbG8gV29ybGQh is decoded to Hello World!.
You can see the output in the screenshot below after I executed the above PowerShell script using VS code.

Check How to Convert Files to Base64 in PowerShell?
Method 2: Using Base64 Module
Now, let me show you another method: using the Base64 module, which provides a more streamlined approach for encoding and decoding Base64 strings.
First, you need to install the module if you haven’t already:
Install-Module -Name Base64Here is a complete example to understand it better.
# Import the Base64 module
Import-Module Base64
# Base64 encoded string
$base64String = "SGVsbG8gV29ybGQh"
# Decode Base64 string
$text = $base64String | ConvertFrom-Base64
# Output the text
Write-Output $textCheck out How to Convert String to JSON in PowerShell?
Method 3: Using Custom Function
You can also create your own function to decode Base64 strings in PowerShell. This can be useful for adding additional functionality or custom logging.
Here is an example.
function Decode-Base64String {
param (
[string]$base64String
)
# Decode Base64 string to byte array
$bytes = [System.Convert]::FromBase64String($base64String)
# Convert byte array to text
$text = [System.Text.Encoding]::UTF8.GetString($bytes)
return $text
}
# Base64 encoded string
$base64String = "SGVsbG8gV29ybGQh"
# Decode using custom function
$text = Decode-Base64String -base64String $base64String
# Output the text
Write-Output $textI executed the above script, and you can see the output in the screenshot below:

Conclusion
In this tutorial, I will show you how to convert a Base64 string to text in PowerShell using different methods, such as using [System. Convert]:: FromBase64String (), using the Base64 Module, etc. I have also explained how to create a custom function to convert a Base64 String to Text in PowerShell.
You may like the following tutorials:
- Convert Variables to Strings in PowerShell
- How to Convert Base64 String to Byte Array in PowerShell?
- Convert Multiline String to Single Line in PowerShell
- How to Convert String to Boolean in PowerShell?
- How to Convert Bytes to Base64 String in PowerShell?
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.