In Powershell, is there a way to save a typed command into history without executing it for later execution?
Well you can always put a comment tag before the command like this:
#Get-ChildItem
And when you are ready to execute, arrow up to the command hit Home then Del, then Enter to execute.
This appears to work too, after some playing with invoke:
$VariableName = "Windows Command"
Then, to execute:
Invoke-Expression "$VariableName"
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.
Many of the command support a -whatif
parameter that you could append and remove later. However, I have to say I like the comment idea better.