I've read in the docs for PSReadLineOption that I can control whether the executed command line is logged in the history. I've tried setting it in a number of different ways, like so.
Set-PSReadLineOption -AddToHistoryHandler $true
Set-PSReadLineOption -AddToHistoryHandler "true"
Set-PSReadLineOption -AddToHistoryHandler "True"
(Get-PSReadLineOption).AddToHistoryHandler = $true
(Get-PSReadLineOption).AddToHistoryHandler = "true"
(Get-PSReadLineOption).AddToHistoryHandler = "True"
I'm receiving a set of various errors about the types not being convertible. This suggests that I'm barking up the wrong tree, trying to fix the syntax for the assigned parameter.
Cannot bind parameter 'AddToHistoryHandler'. Cannot convert value "True" to type "System.Func`2[System.String,System.Boolean]".
Cannot bind parameter 'AddToHistoryHandler'. Cannot convert the "true" value of type "System.String" to type "System.Func`2[System.String,System.Boolean]".
Exception setting "AddToHistoryHandler": "Cannot convert value "True" to type "System.Func`2[System.String,System.Boolean]".
When I ran the command to simply check the current value, I got nothing in return. I mean nothing as in no output at all, no empty line, no error. That confused me additionally.
(Get-PSReadLineOption).AddToHistoryHandler
It's like the option isn't available at all in my PS but is kept for show. Admittedly, turning off the history is rather pointless and not an option that I feel to be needed. In fact, the history works now as I want it to, so my question is rather academic. I played around with the different settings and it bugs the nerd in me that this one doesn't seem to work as expected. I want to understand.
This property contains a script block which returns true or false. If the script block returns true, the value will be added to the history. As an example you can define that short commands like less the 3 character will not be added to the history
Code example:
Check out this site to read more about it: https://petri.com/let-psreadline-handle-powershell