In response to this question, the original requester wanted to know
In PowerShell, is there a way, after typing a long or complicated command, to commit that command into the history buffer, but not execute it?
My solution however was purely for fun, but I wondered how / why it worked on the back end.
$VariableName = "Windows Command"
Then, to execute:
An example with Ping:
I was also able to use PowerShell expressions in the exact same way:
PS H:> $Outlooks = "Get-Process -Name Outlook -Verbose | fl StartTime, Threads"
PS H:> Invoke-Expression "$Outlooks"
Essentially, I believe what is happening is that we are creating a string for the first variable (Exactly what it looks like, straight forward), and then when we invoke our variable inside " " it forces the interpreter to expand the variable, causing it to call the right command.
Is my understanding of how this works accurate? References preferred.