October 27th, 2015

PowerTip: Encode String and Execute with PowerShell

Doctor Scripto
Scripter

Summary: Learn how to encode a string into base64 and execute it with Windows PowerShell.

Hey, Scripting Guy! Question How can I encode a string into base64 and then run it via Windows PowerShell?

Hey, Scripting Guy! Answer Use these commands:

$string = {(Get-WindowsFeature).Where{$PSItem.Installed}}.ToString()

$encodedcommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($string))

powershell.exe -EncodedCommand $encodedcommand

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.