PowerShell Quick Tips : Get-Credential

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to this Powershell quick tip video today we're going to be taking a look at the get- credential commandlet now this is a commandlet that is going to be used in your automated scripts and your manually ran scripts we're going to be looking at more on the manually running of the get credential on this video just because I want to show you guys some little bit of aspects on what you can actually do with the data that you get back from the get credential commandlet but this is definitely something that you can actually apply to your automated scripts depending on how certain softwares actually end up working you might actually need to use um some of these commandlet properties and methods so let's go ahead and let's actually get started at just looking exactly what we get when we do a get credential so I am running the this on Powershell 7.4 and we're running a VSS code so if you are running this in Powershell IC with 5.1 uh there is a slight difference of get credential you usually get a little Windows popup um kind of like a net code framework type of window where it prompts you for your username and password in vs code with Powershell 7.4 this is actually just right below here in the console we're going to get the prompts for our user so let's just put our user here as test account here and we are just going to put a password Here testing this is my password exclamation mark and we're going to hit enter here and we get back a username and a password and the password is going to be a secure string so this is an encrypted string that you can use and you can pass this in usually you would use a get credential to connect to your Azure environment your Ms graph uh M365 environment as well as a bunch of other environments that you need to authenticate with um so this is something that normally I usually actually store it to a variable I usually use my variable name as user credentials or user credential um we can make that equal to get credential and that will actually just go ahead and once again just prompt us for our stuff here so if we do test account and then password test 1 2 3 4 exclamation mark and then if we look at what is inside the user credential we are going to see we get our username and we get our password which is a secure string now right now when we do look at the get credential it just says enter your credential it says Powers shelf credential request now what you can actually do is you can actually customize this to tell the user what type of credential you're looking for also like what script is asking for it so there's actual parameters here if we actually just exit out here of this if we do a dash we're actually going to get a message and a title parameter and this is what you can actually use so we can actually use a title here and give our title of just uh script 1.0 credential entry here and then we can put in a message of just say enter your XYZ credential now XYZ would probably be something like enter your Office 365 credentials if you're doing something to manipulate exchange online or if you're doing something to manipulate teams or graph or if you're using it to manipulate your Azure environment you can say enter your Azure credentials and you can fully enter it like that as well so if we go ahead and we actually run this code here there it says script 1.0 credential entry enter your XYZ credential whereas before it was just Powershell credential request enter your credential so it's a little bit vague and you can actually give a lot more information to the user so here maybe if it actually prompts them correctly let's say XYZ I know is a um password with a email as the username so we're going to do test at.ca here and then our password is going to be test 1 2 3 4 exclamation mark and we have that saved now what happens if you submit those credentials and you get back that it's not correct what you can actually do is you can actually look at what is inside of the user credential we already know how to look at the username it's just going to be username now if we did the same idea here and did a password if we look at what is in there it gives us back a secure string now this actually doesn't really help us it doesn't let us know if the password we entered is incorrect or not but what we actually have the ability to do is if we do a user credential do get network credential and it's going to open up a parenthesis all we need to do is close that parenthesis and then do another Dot and what we can actually do is do a DOT password here and if we hit run we can actually see our actual password so sometimes let's say you're doing authentication to an API and that API cannot support a secure string what you can actually still do is still do a get credential and then you can can pass in this into your API route as the password this way you're not putting the password in plain text in your actual script hopefully that API is going to be encrypted with https and the proper security channels around it to make sure that that password is encrypted in the transmission but of course that is kind of out of your control if it's not API that you yourself have coded and that you're just utilizing uh so something that a lot of people will do is do a secret vault which we will cover that in a future video as well or use the CLI XML files which we've seen on this channel before and you get your credentials in an automated fashion and then you can go ahead and pump those or pump the clear text version with the get network credential do password this way you're still doing it correctly no passwords are manually typed into your script and also you can also use this as a validation on if the credentials don't work maybe maybe something happened in your entry of the password that you typed it in wrong you can simply look at it and say oh I forgot it needs a capital T and then all you do is you rerun this you would just type in uh test at.ca and then your password and then if we look at it now we're going to see it does have a capital T so that would just be an example of how we can actually use this in a manually run script any automated script uh there are multiple ways to actually do this there is one more parameter that I want to show for the get credential we've seen the title we've seen the message as well now let's say you already know what the username should be that these people are entering the password for you can actually go ahead and add a username in here so we can actually say test at J.C here and if we actually run this it just prompts for the password right away you can still see it still uses our title and our message but what it will actually say is password for user and we'll show you the user that it's asking for so you don't need to put in the user that you're asking for the password for in your message uh that will automatically be taken care of by Powershell with the get credential commandlet so hopefully this helps you guys use this get credential and like I said you can use this with the secrets Vault you can use this with the c XML and it could definitely help you automate um a lot of your scripts that have credential validation even if the credential needs to be passed in through plain text you can actually still use the credential as long as you have the get credential uh get network credential open and close parentheses. password and then you can pass pass that in without having it in your script directly if you guys have any command list that you guys would like me to do a video on next please let me know in the comment section down below also please be sure to hit that subscribe button hit that like button also don't forget 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: 576
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-credential
Id: WRXKc0dTcuo
Channel Id: undefined
Length: 9min 22sec (562 seconds)
Published: Mon Jun 24 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.