PowerShell Quick Tips : Getting all powershell terminal history

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to another Powershell quick tip video this one is actually going to expand on one of our previous quick tip videos that we've done in the past the one that covered get history we actually got a really really good question on that video the other day which was asking how can we view all the history of all the Powershell sessions that we've ran and I actually have an answer for you it is is possible to do that with Powershell so let's go ahead and let's just take a look a quick look at the get history commandlet and let's go over some of the limitations on what kind of History we can actually see so here I have a brand new Powell 7 window open if I do get history right now we won't get anything because this is a brand new shell a brand new terminal but let's go ahead and let's just run some commandlets here let's do get service and let's let that finish up here that's all done let's do a get process and that's all done as well now if we do a get history here we will notice that we get our history of all the commands that we've run including our first command that we ran which was get history now this is great for this session but what happens is if I go ahead and close this and let's go ahead and let's reopen up our Powershell 7 terminal here and let me just zoom in so you guys can see exactly what I'm doing and let's do a get- history we actually lose all of that now let's say you wanted to see what you did in your last Powershell 7 shell or your last Powers shell 5.1 shell or anything like that let's see how we can do that now one of the command lists that's going to come in handy for this is actually called get PS read line option now if we just run this as is we will actually see here that there is a history save path and we actually have a path here so let me just zoom out because this path is quite long it actually saves our history to a text file and we can see that it saves in incrementally and we have a maximum history count of 4,096 so what we can actually do to get the history of our entire Powershell 7 terminal history is do a get content and then specify a path and what I usually use is a variable wrapper here let me just zoom in a little bit more so inside of these parentheses what I would do is put a get PS reline option and then do a DOT notation after the parentheses and it's going to be history save path if we do the get content like that here is our entire history of our Powershell 7 commands that we've done in the past here and this will go across all the sessions that we've had we've seen that if we do get history we basically got a blank slate so this is really really good in order for us to get our history and we can even go ahead and just highlight one of these right click on it and then we can go ahead and right click again to paste it and we can rerun that command without a problem and now if we do a get history we will see that we see all the commands that we have just run um so again we can go ahead and get the entire history and we will get that once again now the one thing that you do lose is that nice ability to do an invoke history but like I said you could just copy and paste and that works just as well now the main limitation on this is this will not gather anything that you've done on an ISC or Visual Studio code Powershell sessions so let's go ahead and let's just take a look at that um so if we go ahead and come back to our Visual Studio code we have some code that we've done in our last video for credentials let's just go ahead and let's run this real quick and it's going to prompt us for our password we're just going to put it in real quick and that's that so we've run now some code if we go ahead and do the get history we will notice that that code does not actually show up um so it is purely strictly and you can even really tell with the get PS readline option here even get PS read line like the PS read line is the Powershell terminal read line and the name of the file um by just zoom out here is called console host history so just be aware of that that it is purely what was done on the terminal so if you are one that does a lot through Visual Studio code more than the terminal you won't have your history on that but the nice thing is if you're usually doing it through the ISC or Visual Studio code usually those are more very big scripts that you're probably going to be running and you're usually going to be saving those to somewhere so you kind of have a history of what you've done as well so once again if you just want to get the history of your current session it is just get history and then you can use the invoke history as we've seen on that previous video but if you are in a new session and you're thinking to yourself I really wonder what that command was that I ran in the past past uh maybe it was two weeks ago or something just simply do a get content path as long as you can remember the variable wrapper and do the get PS readline option and then you can simply do a do notation finish for history save path you can go and get yourself that history of all the commands you have run in Powershell now again there is that limit of 4,096 now you can actually edit all of those U details as well with the set PS read line option but I will save that for another quick tip this was really just to show you guys that there is a way that you can get all previous history from Powershell terminals I hope you guys liked this quick tip if you guys did like this quick tip please comment and subscribe and hit that like button as well if you guys have any commandlets or any ideas that you guys would like me to cover as a quick tip please let me know in the comment section down below and be sure to hit that notification Bell to be notified when that next video comes out and I will see you guys on the next video
Info
Channel: JackedProgrammer
Views: 395
Rating: undefined out of 5
Keywords: powershell basics, powershell, windows powershell, programming, scripting, powershell scripting, powershell scripting tutorial, powershell tutorial, how to, powershell api responses, powershell automation, powershell beginners, powershell variables, quick tips powershell, quick tips, learn powershell, powershell for beginners, powershell commands for beginners, active directory, windows server, automation, windows 11, windows 10, get-history, powershell history
Id: 6t1lVdA70d4
Channel Id: undefined
Length: 7min 12sec (432 seconds)
Published: Mon Jul 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.