Skip to content

Instantly share code, notes, and snippets.

@rjygraham
Created July 19, 2021 18:31
Show Gist options
  • Save rjygraham/47f8b06fa3f4b3cac83c96a52f9b4375 to your computer and use it in GitHub Desktop.
Save rjygraham/47f8b06fa3f4b3cac83c96a52f9b4375 to your computer and use it in GitHub Desktop.
PowerShell base64 profile function
function base64 {
param (
[Parameter(Mandatory=$true, ValueFromPipeline)]
[string] $Value,
[Parameter(Mandatory=$false, ValueFromPipeline=$false)]
[Switch] $Decode
)
if ($Decode) {
return [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Value))
}
else {
return [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($Value))
}
}
# Encode
"foo" | base64
base64 -Value "foo"
# Decode
"Zm9v" | base64 -decode
base64 -Value "Zm9v" -decode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment