Last active
March 17, 2023 18:36
-
-
Save cdhunt/42dbe8de803e00b6b3d08435c26e725e to your computer and use it in GitHub Desktop.
A PowerShell function to duplicated the Unix base64 util.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Convert-Base64 { | |
[CmdletBinding()] | |
[Alias("base64")] | |
param ( | |
[Parameter(Mandatory, Position = 0, ValueFromPipeline)] | |
[string] | |
$InputObject, | |
[Parameter()] | |
[switch] | |
$Decode | |
) | |
process { | |
switch ($true) { | |
$Decode { | |
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($InputObject)) | |
break; | |
} | |
Default { | |
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($InputObject)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
You can copy Linux sample code and run in PowerShell without any changes.
kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}' | base64 -d