On Linux or macOS, encoding and decoding with base64 is simple. But on Windows, there’s no built-in base64 command in CMD or PowerShell. That’s why many users search for fast alternative of the base64 command in Windows. The simplest way to convert Base64 encoded/decoded data is to use PowerShell’s ToBase64String and FromBase64String methods. The one-liners below will let you work with strings and files securely – without sending your data to any third-party tools. This guide shows how to use Base64 PowerShell commands to make all Base64 data converts locally.
Cool Tip: Wondering how to cat in Windows? Discover Windows cat command equivalent in CMD and PowerShell! Read more →
⚠️ Why I shouldn’t use online Base64 tools? Online Base64 tools may log or store your input. If you’re working with secrets, credentials, or private files, use local commands instead.
Encode a string to Base64
PS C:\> [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Yo"))
This encodes the string "Yo" to Base64 .
Decode a Base64-encoded string
PS C:\> [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("WW8="))
This decodes the Base64 string "WW8=" back to plain text.
Encode a file to Base64
PS C:\> [Convert]::ToBase64String((Get-Content -path "file.txt" -Encoding byte))
To save the result to a file:
PS C:\> [Convert]::ToBase64String((Get-Content -path "file.txt" -Encoding byte)) `
> file-base64.txt
ℹ️ PowerShell reads file content as bytes using -Encoding byte, which is required for accurate Base64 conversion.
Decode a base64-encoded file
To write the decoded output to a file:
PS C:\> Get-Content "file-base64.txt" `
| %{[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($_))} `
> file.txt
Base64 in Windows vs Linux/macOS
On Linux/macOS, to encode and decode a string, you’d run:
$ echo "Yo" | base64 $ echo "WW8K" | base64 -d
On Windows, you’ll need PowerShell one-liners like the ones above. Unfortunately, there’s no native base64 command in Windows or base64 CMD tool, but PowerShell fills the gap.
ℹ️ These PowerShell one-liners work in both interactive sessions and scripts, that is ideal for automation!
Cool Tip: Wondering how to grep in Windows? Discover Windows grep command equivalent in CMD and PowerShell! Read more →
Conclusion
These Base64 PowerShell one-liners are powerful, but not exactly easy to memorize. If you’re switching from Linux or macOS, the lack of a simple base64 command in Windows can be frustrating. That’s why it’s best to bookmark this page and treat it as your personal cheat sheet. It gives you everything you need to encode Base64 PowerShell strings or decode Base64 PowerShell files – quickly, securely, and without relying on online tools.