How to send Encoded Commands Using SendWait via Powershell

Viewed 151

I encoded a command, because it has curly brackets, that I want to paste into a website. The issue I am having is when I try to use the SendWait command I keep coming up with a EncodedCommand Error. How would I go about pasting the encoded command into a website.

Here is the code:

start-process -FilePath 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' -ArgumentList 'https://www.memonotepad.com/' 
Start-Sleep -Seconds 3

$command = @'
Hello {Number 1},
Hello {Number 2},
Hello "Number 3",
Hello "Number 4",
'@
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes) | clip.exe

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("$command")

I want to be able to paste this data into that memo pad website as is inside the single quotation. Would I have to decode it first or is there another method.

Please Help, thank you!

1 Answers

Note that providing input to another application via simulated interactive typing is inherently brittle. You should consider a proper browser-automation solution, such as Selenium; the third-party Selenium PowerShell Module is a PowerShell wrapper for it, but I don't know if it still works (the project is looking for maintainers).


Create a Base64-encoding of the text you want to paste by simulated typing won't work as intended.

Instead, you must escape the { and } characters in your text - as {{} and {}} - so that the .SendWait method uses them verbatim (rather than as part of a keystroke representation such as {ESC}):

[System.Windows.Forms.SendKeys]::SendWait(($command -replace '[{}]', '{$&}'))
Related