0

I'm wondering if there is any way in powershell to run a command without logging it in the history or the up arrow "buffer".

Something similar to the following in bash.

history -d $(history 1) ; ls

Any help is appreciated!

Thank you

TaTo
  • 46
  • 1
  • 8

1 Answers1

1

You can do a simple Clear-History to clear the entire history or to clear the most recent entry, you can try Clear-History -Id $((Get-History).Id[-1]) but that will leave that command in the history.

There are other ways to skirt the history, which are well explained here: PowerShell's Clear-History doesn't clear history

However, I have to wonder what practical/ethical use would lead you to need to hide a command in the history to begin with.

rbleattler
  • 334
  • 2
  • 11
  • Thanks for your suggestion! i will have to deep dive into them. And to address your concerns, I need to use a bench of different credentials for management of different platform (Vcenter, different AD domains, etc.). When i open powershell i would like to set up variables for all these credentials but i don't feel confident to leave them into my profile. So far the best idea i had was to save lines of powershell to set up the credentials in keepass and copy/paste them into powershell when i open it. Of course i don't anyone to be able to peep the history and retrieve them. – TaTo Jul 13 '20 at 09:18
  • I’d say check out PowerShell Secrets Management. It’s still a WIP but it is accessible. https://devblogs.microsoft.com/powershell/secrets-management-module-vault-extensions/ – rbleattler Jul 13 '20 at 10:52
  • 1
    Thanks for the suggestions! There are two issue with this approach. 1. Cred manager has its own issues (when i update credentials sometimes are not retained) 2. If my account get compromised, they will have access to all my credentials which from a security standpoint is kinda concerning.... – TaTo Jul 16 '20 at 10:33