PowerTip: Encode String and Execute with PowerShell

Doctor Scripto

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

0 comments

Discussion is closed.

Feedback usabilla icon