PowerShell Quick Tips : PowerShell Profiles

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to this Powershell quick tip today we're going to be actually taking a look at Powershell profiles and let me just get into why exactly we're looking into Powershell profiles exactly in the last video when we were looking at the get PS read line options we saw a lot of options if we just actually run the code right here get PS line option we saw a ton of different things it's where we saw where the file is that keeps all of our history but we also saw a bunch of different options like we can actually configure what type of color that we have for a string for the commands for a different comment so as example we can see here the string color is blue so if I do a set of double quotes here my text is blue and I did hint towards that you can actually change this now if you've actually tried this since that video If you go ahead and do a set PS readline option and then you go colors and then we go ahead and we're just going to do a object here and we're going to change our color of our string to let's say we're going to change that to a pound FF 5 00 which is the RGB code for Orange now if we go ahead and we run this we're going to see now if I do a string it is now orange so that's perfectly fine if we do a get PS read line option the amazing thing is it automatically turns it into the code that it actually understands for the color but we can see that it's actually changed to Orange so everything seems nice and dandy but if we go ahead and we close this power session and we go ahead and we open up a new one let me just start up a new one here and resume in if we go ahead and do a string we see that it's actually back to Blue and you might be wondering why exactly that is and that's actually because Powershell is constantly loading a profile by default it always loads in the current user and current host profile so in General there is four types of profiles in Powershell so let's go ahead and let's just take a quick look at what kind of profiles we have so we have our basic profile here which if we just do dollar sign profile we're going to get a path here which is our profile now this is the current user current host profile this is the profile that gets ran last this is the one that will supersede any settings that you set in the other profiles but we can actually see here that we do have a profile.current user current host now what this means it means it's for the current user profile that you're using so in my case I'm using the administrator account that is my user and the current host is actually the Powershell 7 terminal so here we can actually see and this is going to be the current user and current host is going to be this profile right here it is the default profile the last one that gets run so it's the most important one really and if we actually go into Visual Studio code we will actually see if I type in profile here we will actually see I can't zoom in here unfortunately but you will see right here that it actually points to a different profile and that's because vs code is its own host so the current host will actually depend on what application you're using to run your Powershell so just remember that and then there is also a profile called current user all hosts so that's going to affect all your Powershell hosts on your current user and then there is also a all user um all users current current host so that's going to be for all your users and for that specific application and then there is a all users and all hosts this is the first one that gets ran and then any changes that would happen to the code based on the current user current host profile would then take over so in order of Precedence basically the all user all host is going to be the first one that runs then it's going to be the all users current host then it's going to be the current user all host then it's going to be the current user current host I usually recommend really just changing the actual dollar sign profile if you have to make the multiple changes to the multiple environments that you're dealing with I definitely would suggest that because you might not even really want the same color schemes to different ones um based on especially with po uh Visual Studio code where you might have some different add-ins to also modify some colors I really usually set the profile for the terminal only anyways as well that is definitely my use case uh it could definitely be different for every user so let's go ahead and let's actually see if this profile exists so if we do a test path here and then the path that we just have to supply it is just profile we will actually see that it is actually false so by default all these files actually don't exist so let's go ahead and let's create this profile and let's see what we can actually do with it so the first thing that we're going to do is a new Dash item and then we're going to create a type file and then the path we're just going to put that as our profile variable and we're going to force that just to be sure and there it is so we've created our profile now so now if we do the test path profile we will actually see that it is actually true and then we can actually edit this profile pretty easily by just calling notepad uh profile and that will actually open up our profile here now you're going to see it's blank and it is in a notepad here so what I typically recommend is maybe just have a Powershell window or a visual studio code window open and that will actually kind of let you uh just type out your Powershell code a little bit nicer make sure you have no typos in there so something that's very common to actually put in profiles is actually all the modules you work with on a daily basis so if we just do a get module here let me just see what type of modules we have in our um Visual Studio code we have a decent amount and let's just see which ones are actually available here for me toak bring in this might be a longer list there it is so we have a whole bunch uh now you can definitely have even more as well depending on how many you've actually uh installed as well but let's go ahead and let's say we always want to have the import module we work with active directory a whole lot so let's go ahead and let's import module active directory here and let's just go ahead and let me just zoom in here perfect I might have done a bit too many times here let me just ruce that there you go so we're going to do the import module active directory and let's just test it out here and let's really show that all this code actually executes we're going to do a right output welcome to Jack programmers Powershell terminal and then right after our right output here this is where we're going to do our set PS read line option and let's go ahead and let's just set one color here for now we're going to do colors open and close curly brackets we're going to change the color for string and we're going to change that again to our orange color so it's going to be the pound sign FF A500 let's go ahead and let's just copy this code and let's just paste it into our profile here and save it so once we actually have our profile saved let's go ahead and let's close our Powershell window and let's go ahead and let's reopen it now you're going to notice it so here it is it just loaded in the active directory you saw it load in and then we also get our welcome to Jack programmer Powershell terminal so it even executes that right output and we even see here that it does say loading personal and system profiles took a little bit of time it took about 3,000 milliseconds it's not that bad especially we loaded in a module so if it's modules that you're using all the time and you're trying going to import them anyways it just saves you that time you don't have to remember to import those modules and then what we can actually even do as well is then you a string and we will notice it is already orange so that is great and you can do a lot of other changes to your profile you can set to only save certain history um which if you want guys want to see a video on that I can definitely make a video on that if you let me a comment down below where you can actually create a function that will determine what gets saved to history and what doesn't so you can actually specifically say any get Dash commandlets don't save that to the history I don't really need to know but anything that otherwise make sure you write it to the history because that's actually a change we don't necessarily really care about gets because we will get is not a very harmful commandlet but everything else might harm the system so we actually want to save that to the history and that just limits how much stuff gets put into the history easier to find what actually has been done on a system there is a bunch of different use cases as well like I said importing all your modules customizing the colors for your Powershell uh terminal as well especially if you are color blind uh especially for the colors of green and red you can change the error and change um if we just do a get PS readline option here we'll actually see that there are quite a bunch of green and red options and the red is error so let's say you wanted to make error a little bit more readable um you can definitely change that to a color that you can actually read uh which is much much nicer so that is really profiles in a tidbit uh very very quickly if you you guys want to see the add to history Handler and how we can actually create our own functions to determine what gets saved to history please let me know in the comment section down below if you guys have any commandlets that you guys would like me to take a look at at these quick tip videos please let me know in the comment section down below as well make sure you hit that subscribe button hit that like button also 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: 483
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, windows server, automation, windows 11, windows 10, powershell profile, powershell profiles, set-psreadlineoptions
Id: 1zm2H91sldQ
Channel Id: undefined
Length: 12min 31sec (751 seconds)
Published: Mon Jul 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.