Richie
Richie

Reputation: 5199

Decoding single kubernetes secret using powershell

I've managed to get my hands on a Powershell one liner that will get all kubernetes secrets and base64 decode them.

kubectl get secrets -o json | ConvertFrom-Json | select -ExpandProperty items | ? data | select -ExpandProperty data | % { $_.PSObject.Properties | % { $_.Name + [System.Environment]::NewLine + [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_.Value)) + [System.Environment]::NewLine + [System.Environment]::NewLine } }

The above works. I've been playing with trying to modify this command to work for a single secret like below without luck:

kubectl get secret mysecretname -o json | ConvertFrom-Json | select -ExpandProperty items | ? data | select -ExpandProperty data | % { $_.PSObject.Properties | % { $_.Name + [System.Environment]::NewLine + [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_.Value)) + [System.Environment]::NewLine + [System.Environment]::NewLine } }

Could someone share their knowledge with me to help me through this one?

thanks

Upvotes: 1

Views: 2412

Answers (1)

Richie
Richie

Reputation: 5199

Thank you @mdaniel your suggestion solved this for me.

kubectl get secret mysecretname -o json | ConvertFrom-Json | select -ExpandProperty data | % { $_.PSObject.Properties | % { $_.Name + [System.Environment]::NewLine + [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_.Value)) + [System.Environment]::NewLine + [System.Environment]::NewLine } }

Upvotes: 5

Related Questions