Use CMD to echo a Script Block to an Encoded Command


I like quirky and odd things.  Encoded commands are nothing new, but check out this method for generating one.

If you echo a script block with cmd.exe /c, in a PowerShell host, you receive an encoded command (and a couple of other populated parameters) with which to call PowerShell…

 


cmd /c echo {while ($true) {Write-Output `
"Now as I was young and easy under the apple boughs
About the lilting house and happy as the grass was green,
The night above the dingle starry, 
Time let me hail and climb 
Golden in the heydays of his eyes, 
And honoured among wagons I was prince of the apple towns 
And once below a time I lordly had the trees and leaves 
Trail with daisies and barley 
Down the rivers of the windfall light.
 "}}

 

My script block continually echoes the opening of a rather magnificent poem. The cmd /c echo converts it to this:

 

capture216

 

I can then take that encoded command and supply it to PowerShell.exe:

 


powershell.exe -encodedCommand dwBoAGkAbABlACAAKAAkAHQAcgB1AGUAKQAgAHsAVwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIABgAA0ACgAiAE4AbwB3ACAAYQBzACAASQAgAHcAYQBzACAAeQBvAHUAbgBnACAAYQBuAGQAIABlAGEAcwB5ACAAdQBuAGQAZQByACAAdABoAGUAIABhAHAAcABsAGUAIABiAG8AdQBnAGgAcwANAAoAQQBiAG8AdQB0ACAAdABoAGUAIABsAGkAbAB0AGkAbgBnACAAaABvAHUAcwBlACAAYQBuAGQAIABoAGEAcABwAHkAIABhAHMAIAB0AGgAZQAgAGcAcgBhAHMAcwAgAHcAYQBzACAAZwByAGUAZQBuACwADQAKAFQAaABlACAAbgBpAGcAaAB0ACAAYQBiAG8AdgBlACAAdABoAGUAIABkAGkAbgBnAGwAZQAgAHMAdABhAHIAcgB5ACwAIAANAAoAVABpAG0AZQAgAGwAZQB0ACAAbQBlACAAaABhAGkAbAAgAGEAbgBkACAAYwBsAGkAbQBiACAADQAKAEcAbwBsAGQAZQBuACAAaQBuACAAdABoAGUAIABoAGUAeQBkAGEAeQBzACAAbwBmACAAaABpAHMAIABlAHkAZQBzACwAIAANAAoAQQBuAGQAIABoAG8AbgBvAHUAcgBlAGQAIABhAG0AbwBuAGcAIAB3AGEAZwBvAG4AcwAgAEkAIAB3AGEAcwAgAHAAcgBpAG4AYwBlACAAbwBmACAAdABoAGUAIABhAHAAcABsAGUAIAB0AG8AdwBuAHMAIAANAAoAQQBuAGQAIABvAG4AYwBlACAAYgBlAGwAbwB3ACAAYQAgAHQAaQBtAGUAIABJACAAbABvAHIAZABsAHkAIABoAGEAZAAgAHQAaABlACAAdAByAGUAZQBzACAAYQBuAGQAIABsAGUAYQB2AGUAcwAgAA0ACgBUAHIAYQBpAGwAIAB3AGkAdABoACAAZABhAGkAcwBpAGUAcwAgAGEAbgBkACAAYgBhAHIAbABlAHkAIAANAAoARABvAHcAbgAgAHQAaABlACAAcgBpAHYAZQByAHMAIABvAGYAIAB0AGgAZQAgAHcAaQBuAGQAZgBhAGwAbAAgAGwAaQBnAGgAdAAuAA0ACgAgACIAfQA= -inputFormat xml -outputFormat xml -noprofile -nologo

 

Perpetual PowerShell poetry:

 

capture217

Comments (0)

Skip to main content