Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active April 25, 2016 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaykul/55544f22ab8f49141454e841eeaf923a to your computer and use it in GitHub Desktop.
Save Jaykul/55544f22ab8f49141454e841eeaf923a to your computer and use it in GitHub Desktop.
Breaking PowerShell since ... *muffled sounds*
<!-- This breaks ConvertTo-JSON for strings -->
<Types>
<Type>
<Name>System.String</Name>
<Members>
<ScriptProperty>
<Name>AsBase64</Name>
<GetScriptBlock>
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($this))
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>FromBase64</Name>
<GetScriptBlock>
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($this))
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
<Types>
<Type>
<!-- This gives me the Base64 functionality, without breaking ConvertTo-JSON -->
<Name>System.String</Name>
<Members>
<ScriptMethod>
<Name>ToBase64</Name>
<Script>
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($this))
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>FromBase64</Name>
<Script>
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($this))
</Script>
</ScriptMethod>
</Members>
</Type>
</Types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment