Learn PowerShell with Active Directory in Less Than 2 Hours

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back fellow Powershell Engineers we are now going to switch gears and start working with active directory and the active directory module for Powershell now some of my first exposure to Powershell had really nothing to do with a lot of the previous chapters um I mean I kind of did but I didn't know at the time that what a lot of those key Concepts were but it did have everything to do with managing users specifically automating the management tasks of users to create consistency and reliability so that came with using the active directory module and it has numerous commandlets that allow us to manage users groups computers and more within active directory so in this unit we're going to explore more than just using these tools but how to do how to develop small scripts that create massive massive leverage for us as systems engineers moreover is the book is the course progresses I should say in the security and Cloud Concepts many of the examples we will focus on will be related to active directory so before we start working with it directly in power shell you may be thinking hey I don't have an environment to do this in so we're going to actually build an environment a Windows our own domain controller with active directory we're going to use Oracle virtualbox to do that and all of this is totally free you can get the iso for Windows Server 2022 for free on a trial basis to use I think it gives you something crazy like six months and then also uh like I said the Oracle virtualbox which is also for free so let's go ahead and move on into the next lesson to set up that domain controller hello and welcome back fellow Powershell Engineers we are now going to switch gears as I mentioned in the intro to installing our Windows Server 2022 test environment and actually we don't need virtualbox first on that we need our ISO for Windows Server 2022 you can find this on Microsoft's evaluation center uh website I do have the URL right there uh en US eval Center file the rest of that there so let's go ahead and click on download the ISO and it's going to want us to input some information there oh am I going to docs my phone number I don't think so I'm sure you guys could Google it I'm sure it's just sitting somewhere all right oh country code all right Perfect all right uh I'll take the 64-bit Edition English and I thought before it had oh no no that's when we get to the install so I'm gonna go ahead and pause the video I would have thought that'd be a little faster given my internet connection but we'll uh pause the video wait for that to download and then we'll go ahead and download uh virtualbox all right welcome back now we see that this is nothing you left oh we see the iso is downloaded so let's go ahead and download Oracle virtual box and get that installed so we can build our virtual machine for um making our test environment so virtualbox Windows host perfect a little bit of a quicker download get that installed all right we're going to go ahead and click next go just work our way through this and we'll install the dependencies go ahead and do another pause point on this don't need to sit here on this too long actually that didn't take that long and here we go we've got it now all we need to do is add a virtual machine I'll put it this I'll just put it in Powershell engineer Dot com folder okay what did I do didn't I do the right thing select a virtual machine file oh because I'm clicking add I need to click new very good all right yeah I'll just I'll just leave those right there we'll call this win server 2022 um let's go up to at least two processors if you want it to run well and we'll go up to four gigs of RAM create that that's no problem all right um now we need to go to settings and we go to storage and down here to the disk drive and we'll choose a disk file and we'll pull that from our downloads okay cool now we're good to go ahead and give it a start that's all you have to do and really without the download time I'd like to point out that we're pretty good shape here so far time wise and we see that it's loading fill out our window here all right do next do install now I'm going to keep doing some pause points actually just in case all right so we do want the desktop experience although we could certainly run it without that and we'll do the standard all right we'll go ahead and accept the agreement there do a custom install our 50 gig drive that we made and we'll go ahead and do another pause Point although things seem to be moving a little quicker than normal which is great all right it's restarting again super super fast we don't need to boot from that just so you know so I didn't edit the settings now the thing to do uh would be to go pull that ISO off the settings or else I'll do that every time not really a huge deal um and if you're like me I wind up redoing these a lot anyway so or I might convert this VM I mean you could just easily make a new VM but you know might convert this VM to something else so or or if you board the system which certainly done that as well uh let's go ahead and give it another pause while it's loading this screen all right it actually rebooted one more time and then just got us back to this so go ahead and make a password that you're going to remember and we'll go ahead and do a finish and bam we're ready to lock to log in so on the input if we go to input keyboard That's How we'll send our control alt delete and we'll log in with our password that we set earlier um I just turned this on automatically on my VMS we could try the admin Center we're not going to do that actually for this got all these notifications cleared here so actually what we want to do is go ahead and go to manage and add roles or features we're going to get active directory added on there and we click next role based I'm talking about this machine and what we want is active directory domain services and we'll add everything that it's got with it we'll click next again it's going to add.net edds and we go ahead and give that an install and again everything's been kind of going pretty smoothly pretty quickly here I don't even think I'll bother pausing because I don't think it's actually going to take that long yeah actually I take it back I'm gonna pause all right um it is good to go now so that's installed but you'll notice right here on our notifications that we have some post deployment configuration so what we're going to do is go ahead and promote this to a domain controller and when we do that we're actually going to add a whole new Forest and we're going to name that Hogwarts org and here is where we're going to we're going to wait for it to load all right now we're back let's do I don't know why that took so long actually uh I think two if you guys just click on this while it's doing that loading thing I I don't know if it was a coincidence or not but when I just clicked on it it seemed to load like I don't know why I was doing that but we're good to go set a password um all these settings are fine oh yeah we don't we won't recruit that uh delegation and we've got to create the net bios name I believe it should Auto populate that yep Hogwarts it's good looks good verifying the prerequisites this also might take a little bit actually while we're waiting on that let's go ahead and try to up our display resolution here um it's a little bit better keep that let's see if we go there we go that's more what I'm looking for there we go okay we got some warnings here but everything completed sorry I keep trying I don't know why it keeps resetting this guys oh here we'll get that off of there all right so we'll go ahead and do an install I'll keep toying with the uh the window here all right so because it's not quite perfect what I've got here I'll have to like scroll up and down that's not a huge deal all right so wrapped up it's about ready to restart we'll go ahead and let it uh restart we will let it it's not telling us at this point I assume you've probably already paused the video a bunch of times because yeah for whatever reason setting up the uh the roles and enabling active directory I mean it's like almost taking as long if not longer than to download make the VM and install Windows it's kind of wild all right we're getting close here all right so it's loaded finally and uh go ahead and do a control alt delete and we see that we have Hogwarts here is the domain that we're logging into now that this is a main controller for our Hogwarts domain so go ahead and log back in and scroll down here and we've got server manager we don't need that but just one final thing to check so we'll search for active directory users and computers go ahead and pin that there to the taskbar because we'll be checking that when we start making some users and interacting with them via Powershell and you'll see it's got some OU's built in automatically we'll build our own OU's but if you made it this far which I assume you have because absolutely this is just steps you gotta follow it's super easy I'm I'm sure this is not too hard for you guys just annoying waiting for it all to load but uh congratulations you now have your own test domain controller and we'll go ahead and move on to the next lesson hello and welcome back fellow Powershell Engineers we are now going to mess around with the active directory module let's go ahead and give that an open and uh let's actually take a look at our properties here up the font size as you know I like to do let me modify shortcut okay I don't know what's up with that you know weird stuff happens like that in Windows Server I feel like all right and we'll go ahead and move the directory to Powershell guys I like to keep that stuff in too because I don't want to sugarcoat hey you know weird stuff pops up sometimes I mean that's just part of systems management right so we are now we've got our admin uh Powershell and let's go ahead and import the active active directory module and bam that is now imported so we're now able to uh to use those active directory commands that's all you had to do to be able to use them now let's go ahead and do the get command uh to take a look at what is actually in the active directory module as you can see there's quite a lot unlock 80 account we'll be doing that later set 80 user setting uh 80 uh user stuff removing all the different remove commands and you know what's interesting uh what I like about this is that you know again Commandments are verb noun so you can just kind of browse to it kind of gets you geared more to thinking what am I what action am I doing and then what am I doing it on right so there's a lot of stuff here we're certainly not going to go over all of it in our class again we're going to focus on uh users and uh groups so that's it for this lesson I just want to import it and uh show you what commands are available or how to take a look at what commands are available so we'll see in the next lesson all right welcome back fellow Powershell Engineers we are now going to begin working with organizational units Now to create your first organizational unit in your newly minted domain you can use the new ad organizational unit commandlet that'd be new Dash ad organizational unit we're going to create a top level OU to distinguish from default uh uh from the default domain OU's that are made automatically in active directory which we've already seen down here these right here but we're going to just start off by doing that not in the GUI of course but we're going to do it with Powershell so let's go ahead and make a new organizational unit and I try to do a tab complete there uh yep and we've completed that out name I'm gonna call it Hogwarts School for witchcraft and widget Wizardry again uh that copyright's owned by whoever owns it not me same with all the examples I use and we'll do the path now this is the path uh within ad so DC equals Hogwarts DC equals org and that should be all we have to do to make that organizational unit if we look go over here and look here we'll do a refresh and we see we now have our organizational unit there so from there we're going to make a more organizational units for the staff students and then within students we're going to make an organizational unit for each of the houses in uh in Hogwarts so let's go ahead and do that and what's great about the command histories we can just go up and now we can place things inside of our uh new OU but we'll have to add the OU in the path right so hsww now I want to make a staff oh you I want to make a review and we can just go double check that those are made by just doing a refresh we see that those are there now and then within students we're going to make one for each house as I said so we'll do students add that to the path and we will make one or with Gryffindor huffle Puff and then Ravenclaw and of course Slytherin all right so let's go ahead and go back to our active directory and check that those are all there uh we can drill down this way actually and if we look we now see Gryffindor Hufflepuff Ravenclaw Slytherin boom just that like that that easy I'm also going to go further back up and make one just called a top level one called powershellengineer.com and that's just going to be so we have just so we have the Powershell name in there when we see uh we're working through this stuff and that will be it for this lesson you now know how to make organizational units and again I'd like to point out how quickly we've come we have a test server we've got ous we've got a new domain controller and it again you can do it I'm just doing this on my home computer right so very easy to do and Powershell makes making these OU's honestly I think this is a little simpler just using the commands that's a lot of people think they don't want to jump in uh to the Shell to the command line but I mean look how easy that was I mean just just seconds I hand typed I didn't even copy and paste anything so Powershell keeps it simple gotta love it I'll see you guys in the next lesson hello and welcome back fellow Powershell Engineers we are now going to move on to creating active directory users and we're going to do that with of course Powershell and we're going to be using the new ad user command and what we can do actually is do a get help on that just to take a look gonna update our help that's something I should have done in uh right away I'm gonna go ahead and leave that in there though because you know that does happen and if we're all in the same boat here too I I don't like leaving stuff like that out um sometimes too I've seen with the get help that we uh we get uh some failures on that so don't be surprised if there's some failures coming up not everything gets updated but we're almost through the alphabet here it's cranking its way through perfect actually we didn't get any failure so that's great um yeah so here we are we have our new way to use your help information creates an active directory user as you can see there's a ton of different uh parameters here that we can work through um you can set commonly used user property values by using the command lit parameters you can set property values they're not associated with commandlet parameters but using other attributes parameter so that's somewhat important if you're going to add uh parameters not specifically uh listed in here or properties I should say of the 80 user so and I like this too that it's bringing up that you can bring this is commonly used with comma separated value files uh because it certainly is and um also get 80 user we'll be using the leader of course remove ad users set 80 user uh or some other uh commands there so let's go ahead and do a clear picture I'm on the right area there there and new ad user and we are operating in the Harry Potter universe so let's do Harry Potter and the Sam account name H Potter we'll also need a user principal name we'll just do each Potter at hogwarts.org [Music] our path we'll go back to our old OU path there so we want to put him in Gryffindor we'll keep it uh keep it canonical with the movie Here whoops OU equals perfect students [Music] um lots of typos here .org all right uh all right so for the account password we're going to put in parens we're going to use the convert to secure string so it really doesn't like it won't accept a plain text password right and we'll just do Gryffindor and playing text we'll have to have and we'll force that just in case it complains and then finally we want to make sure the account is enabled we'll pass out a Boolean true and Bam there we go there we have it let's go give our 80 a check and there we see our Harry Potter user none of this information we actually filled out which is all right we see our H Potter and then uh actually we don't have every uh we can't see every property there let's go ahead and go to view and do Advanced features and then that way students will go down to Gryffindor we get our attribute editor and that's where we can see there's a distinguished name the whole OU path there um there's our user principal name so again this is where you can see every every field possible and this is kind of what that get help was talking about that not all of these are parameters but uh you know there are properties that are correlate with a parameter but you can still certainly use Powershell to set any of them so um all right so that's it for this lesson let's go ahead and move on to the next one hello and welcome back fellow Powershell Engineers we are now going to take a look at the get 80 user commandlet this will be how we get a hold of a ad user and AD user and uh to basically evaluate it do whatever we want to do take a look at what properties it has set so we'll go ahead and give that a go get ad user and we'll use the identity parameter to specify the username we'll use our hpotter user and there you have it pops us back the information that we want there about that user so we can actually do get a little more creative we can use get ad user to utilize filters as well so say if we just want to get all of our enabled users we would say enabled equals we'll go back we're still using our standard Powershell operators and we're going to use the Boolean true again this is why the fundamental stuff way back in chapter two or unit 2 was really important so we get our administrator user and our Harry Potter user which is pretty sweet um but this this being Powershell you know let's go ahead and take a look at setting a variable to a user right to take a look at it so we'll just do 80 user is equal to get 80 user identity H Potter if I take a look at my 80 user variable now I have all the I have not all the properties but I have some of the properties inside of uh this 80 user variable of the hpotter user so we can do take a look at some of the properties if we wanted to do user principal name H powder at Hogwarts so we can actually do um really any of those right there we can take a look if the user is enabled and so forth so very useful especially if you were building maybe a script that was querying users or you were trying to find a user you would capture the user inside of a variable and you could start performing Logic on it right um and that's that's definitely pretty handy now maybe you don't want uh everything that you see here you only want some specific Properties or you want some that are aren't given by default right because it doesn't give everything by default so what we would do then is use the get 80 user the identity parameter with h Potter type that to the select object parameter or commandlet I should say and we'll just get name Sam account name and user principal name I guess bam and that's all we have so if we were to go ahead and do that same command which just do the up arrow in our Command history the user is equal to that we take a look at our 80 user we'll see that we only have those values and Note 2 that that is in a hash table so definitely pretty useful to start getting at whatever information you need about a particular user from active directory with Powershell so that's about it for this lesson we'll go ahead and see in the next one hello and welcome back fellow Powershell Engineers we're now going to switch gears and start looking at how to set user properties with the set 80 user commandlet and Powershell and that is actually really simple to use as you might Gather By how easy the other ones are at this point I'm going to do a set 80 user and we'll do our identity parameter and we'll do a Potter again and basically uh depending on the parameter in question we would just do uh the name of the or the name of the property I should say it should correlate with the parameter in general although I don't believe they all do but certainly email does so we'll go ahead and do harry.potter hogwarts.org and boom that's set let's go ahead and validate that we could do that with a get 80 user but I'll just like seeing it with the GUI as well all right that's set not a big deal what if we want to go ahead and set more than one property well maybe we goofed up and our naming scheme is run gosh knows I've done this actually it's why I like writing Powershell for these kinds of uh issues right here to get these uh things types of things formatted correctly so let's go ahead and do the office phone parameter and we'll go ahead and do a 800 555.000 number now we're setting two properties at once pretty sweet go ahead and validate that we see this change and we set our telephone number so definitely you don't need to do one-liners over and over again to set the properties you can uh you know make that all one command definitely worth knowing another thing we can do with steady set ad users enable and disable a user so let's go ahead and do set 80 user our identity again and this time we'll do the dash enabled parameter and we will do a colon then provide it with a Boolean so we'll just say false for enabled and it go it takes that command no problem now if we go back here it looks like he's still enabled but what we need to do is actually right click white space and refresh that and we see the little down arrow there indicating that he is in fact disabled now if we double click that go to account and we'll see right here account is disabled so this is something you may want to do if you're saying if you have like an off-boarding script uh you know you would set it this way to you can just have this command ready to go you could have a disable button or have it as part of a different workflow and disable your users with you know potentially one click when they're ready to go so definitely very cool we'll go ahead and re-enable a Harry and just Triple Dog check this is uh good to go he's re-enabled and that is about it for set 80 user really straightforward a very very powerful command very useful for automation so we'll go ahead and see you guys in the next lesson hello and welcome back Powershell Engineers we are now going to move on to resetting the password for an active directory user and the way we would do that is with the set ad account password commandlet and we'll do that with the identity parameter similar to our other commandlets we'll do a reset uh parameter right here that doesn't need an argument set the new password to hurt ring new password go ahead and set that string go ahead and force that and and let's go ahead and give it a run all right so that should be reset and then what we need to do is actually go back to our set ad user commandlet your identity again and we need to do the change password at log on set that Boolean to true a uh it will force them to change their password again obviously for security reasons we wouldn't want to know their password so give that a set and then if we go check on our user um okay let's see what happened here password log on oh I already had it open from earlier so Note 2 that yeah that will not refresh on its own you'll have to close and reopen it so I actually already had that open but that did get set um that check box so remember to close your user when you have them open already and that should be it for resetting a password for a user and active directory so let's go ahead and move on to the next lesson hello and welcome back Powershell Engineers we are now going to go over how to unlock an active directory account very straightforward you know the classic verb noun with the commandlets will always help you out there right so we're going to do unlock ad account leave me typing if I didn't have a typo and just a simple command all right so just went ahead and unlocked the account wasn't actually locked but uh that what you would be able to verify and this is exactly how you would do it this is a real straightforward commandlet and um definitely something that you know takes a few clicks when you're going through active directory in fact we can go over that right you'd have to go here click unlock account and click apply so if you had some type of user management tool you were using just for your uh your help desk or for anybody in your team your your technology team uh you know having this be a one one click just uh and typing in the username uh thinking maybe with a Windows Form and I begin ahead of myself here to the Automation and focus section but it might be a good use case for that so all right we're gonna go ahead and move on to the next lesson hello and welcome back fellow Powershell Engineers we are now going to make a new Active Directory Group and then we're going to add our user to that group so to make a new group what you do is you use the new ad group commandlet specify the name of the group with the name parameter now we've got to define the path of the group within our active directory structure here let's put this in our students OU like our group scope global all right now if we go down to active directory we've got our students we see our new quidditch players group Security Group and notes that it's a Global Group as well so now we just want to add our user to it and to do that we will use the add Dash 80 group commandlet add 80 group member excuse me and we always go back to our identity parameter but this being the identity of the group at the user for this particular command that it would be members for the group or for the user or comma separated for multiple users all right let's go ahead and look at our user there and should see that the Harry Potter user is in the Quidditch players group so it's really really that simple to make groups and AD groups and again you can do get 80 group commandlet whoops set that to a variable and we can take a look at the group from uh the point of view is a Powershell object and we can start digging down deeper into this as well so that is about it for groups we're going to go ahead and move on to the next lesson hello and welcome back fellow Powershell Engineers we are now going to switch gears and take a look at Automation in focus for our active directory module so with that we have a I have a shell of a script that I've already made here that we're going to kind of build out the logic for so we can take a look at it I built out the graphical user interface with Windows forms because I didn't want to spend too much time on that so let's go ahead and open the ISE and we'll give this an open here and I was already there make this a little smaller here I'm already zoomed in um even though we're inside of ISE let's go ahead and set the execution policy actually done this already I don't know if it's gonna hold up just because it's a Windows Server sometimes it does something a little bit different um yes to all for that set it to unrestricted let's go ahead and give this a run and we'll do a run once and there we have it we've got our form here first name last name and a combo box with nothing in it again we saw our button logic here there's no button logic that's what we're going to build out right now so all this will be is just a little form to make a user automatically and let's go ahead and start building out that logic I do want to point out before we start that though I am doing the import module with active directory at the top of the script um so that will give us the ability to have the active directory commandlets that we need to add the user so before we actually add the button logic though we do need to add our drop downs in the combo box and the way we do that is the add method which is a method that can work on the items property so I want to reference the combo box and then we'll reference items and we'll go ahead and reference add and that should just be about it so I'll just copy and paste that line three more times so we can go ahead and build out the rest of the options all right let's do it and do save let's see what that looks like so we still have our default text of combo box so we might want to get rid of that or maybe we can leave it I don't know either way but we've got our options now um actually let's go ahead and blank that out here save give it a run yep there we go that works that looks a lot better so I look at that stop there now we're going to do a couple of different things here we want to First capture our text box variables right so I'm going to capture our first name and I want to just put it in a first name variable and we'll do text box one dot text I also want to go ahead and capture the last name and with that we'll do text box two now I'm going to use a method we haven't actually used yet um at least I don't think I'm gonna get the first initial so the in first initial the first character of the first name and the way we're going to do that so we're going to say it's equal to the first name but we're going to use a method called substring and actually I'm going to bring that back up just pop it up too quick so right here you'll see the Syntax for using it the int start index so this would be the character placement that I'll start and then oops that went away but the other one is the length so how many characters of the substring do I want to get so I'm going to start at Place 0 of the first name and I only want one character so that should get us our first initial so the purposes of our um just our name just having the name variable or yeah the name property um we'll have our name variable and I just want that to be first name and plus a space then the last name so just our full first and last name will be our name now our Sam account name oh I want that to be this would be like our username right so I want that to be our first initial but our first initial likely is going to be uppercase and just in case just to make sure that it is we're going to use the two lower method so we'll do that now what that does is it makes the string that the method is being run on or the object the method is being run on takes it down to lower case and then we'll view the last name the full last name so first initial last name to lower and same principle there and we also want to set our user principal name that'll just be the CM account name now again all these are depending on how you do it in your environment this is kind of a common format that I've seen so that's what we're going to go with right um so we're gonna do that plus remember our domain name likely this would be your email doesn't always line up perfectly like that right but do it it's dot org we also need where are we putting this user within the active directory structure right so that would be the path will be equal to U equals and this is where it gets a little tricky right this is where we put our combo box right because depending this is where we're going to be creating the user so we're selecting that and this is sort of this I mean that's sort of this is a piece of the automation right you're you're doing a lot for your clicks by putting the having the OU selection just be a drop down so we will do the combo box one dot text don't forget we're comma separating these so we do need another comma right here and then we can go ahead and create the rest of this bam just like that and we can make a default password the account password I get that uh combo box again add a string one two three now I think that's about oh we would absolutely need to start so let's go ahead skip down the line we're going to want to do our new ad user only at where we're going to specify or Define these parameters which will get mapped to ad user properties so our name will just be our name Sam account name Sam account name user principal name your user principal name path will be our path now I think all we have left would be the account password and remember we're going to do the convert to your string password plain text just like before and we'll force that and last but not least if you remember from when we created our new user give you a second what was it gonna make sure it's enabled and to do that we will set it to a Boolean so that should be it for the logic um I think that's it so let's go ahead and give that a run yeah I think we're good and let's see if we can't make a drink and we want to put him in house Slytherin you have no feedback at all that's funny well didn't really think about that I guess we could have changed the title there but let's go ahead and check our ad didn't complain with any errors so I think we should be good bam there is our user Draco Malfoy in Slytherin [Music] D Malfoy worked so the string to lower worked it's great let's go ahead and change our view options so we can see the advanced features whoops no attribute editor or a user principal name was there yep perfect and obviously our path work because Draco is in the right path yeah gosh there's a lot of properties oh yep we've got our name there yeah I think we're good obviously there were more properties we could set uh here that we didn't set you know we didn't even actually set the first name last name um email you could set all that stuff but uh yeah we've kept going on this obviously if you're building a full-blown script that would work but this is just a simple Windows forms Powershell uh script that just adds users and you can see how this will really start making things simple if geez you know if you don't remember what the format is of the UPN or the email address uh it just does that does your default password for you every time so the user is good with that it keeps it consistent which may not always be a good thing security for folks out there but yeah um yeah it's just a really great automation you know like I like I said earlier I I've made this in a lot of organizations I've worked with a version of this definitely way more complex um because there's a lot of other things you know groups that we want to add by default and that was something we didn't do here either um that would be super easy to just add to the group um if you had a Slytherin group based off of the combo box yeah you can have corresponding groups with these even though the group formats um yeah yeah there's a lot of stuff you could you could do here so that is about it for this lesson automation with active directory Automation and focus way to go Powershell Engineers we'll see in the next lesson hello and welcome back fellow Powershell Engineers we're now going to move on to AI in focus and as I've alluded to before formatting of commands is one of my favorite use cases of chat GPT I don't want to hunt down every parameter every time I'm writing a script it is time consuming and I often find myself scrolling through other people's scripts for examples when I just can't find the right example right away with Google or stack Overflow or whatever so so let's go ahead and command uh check GPT let's have it uh write a Powershell command that adds a new user to active directory that includes parameters for name display name uh and write it out write a Powershell all right yeah first and last name initials an email all right classic identifies it as Pearl all right uh dude do you have the interesting thing about this is that it doesn't have a path I have a bad example right because it doesn't even have a uh OU path all right let's go ahead and give it a run let's say we know that though this is again why okay yeah so where did I put that that user and find it disabled John Doe user what's user's gender okay all right so we didn't specify it so I didn't put it let's put our John Doe right here right so we'll bring John Doe back to uh and staff maybe right did set these fields it did do the initials got the example with the email there I mean actually you know Sans not having the path and really I didn't tell it to do a path so I guess that's correct um I thought you would have had to specify that that was a again reveal my own ignorance on this sometimes it's okay he I just never run new ads or without a path right normally I know where I want to go we're not just dumping stuff straight into the default users uh so we could add go back to our existing code we do have the parameters here so let's Loop this back right this would give us the ability to kind of correct what we were talking about with the automation and that's sort of my whole my whole point with this was that uh we didn't have all the the names we needed there all the parameters we needed so we've got given name surname display name and initials oh in the email it's actually yeah all of it we need we already had a name so if we go back to ISE okay just dump all those right there yep we don't want uh we don't want to do these obviously so we're going to do our first name it's your name which would just be our last name explaining which is actually what we wanted from name and I just noticed didn't have that we did have it I actually removed it in our initials right so we'll have to build our initials uh um variable that would just be our first in and our last initial which is not a variable I've made yet but you can just copy and paste this just got our last initial we're doing the same substring off of our last name initials to email oh there's that name from earlier that I I just copy and pasted that in the wrong spot okay email we can actually just use our user principal name for email so it won't make a separate variable that works pretty well to squeegee there you know we don't really need it don't want to run a code selection I want to run the whole script let's do a Hermione Gryffindor let's see if that complains no errors down here so wow and Gryffindor with all of our fields we talked about on top of the things that earlier VPN Etc in the correct OU as well so yeah maybe one other thing I would tweak with this is just uh box a little bit bigger the not the Box the form that maybe as wide as we want so just bumped it up 200 pixels there yeah student Creator I don't know it gives us some real estate here to add some more stuff potentially um but yeah that way we can read this kind of drop down again real simple but what we did there you know it's really pretty sweet we uh used AI to to generate the rest of these parameters off this command I mean if you didn't know what this command was uh you would have it as well and let's just worked ready to go pretty straightforward text there now let's see if we can just recreate our whole process here I'm gonna get a little crazy and let's see if this works all right foreign that's really really specific let's see what it gives us it's thinking I like it maybe hopefully didn't crash been a weird phrasing here actually maybe you can't do it I don't know you know I've actually used this to create uh Windows forms uh partial scripts before and it's actually done it pretty decently so let's go ahead and give it a shot again go ahead and just refresh the whole thing because it seemed to kind of be flaking out oh Jesus look how quick that is maybe I had it good to go already knows that it's Powershell oh nice yeah this is definitely way better than mine oh the generic groups the user oh wow wow that is fantastic oh and the Windows Form show message box all right this is pretty cool let's give this a shot this looks great way better than mine also how long would that have taken me to write it all right I do want to look it over I always am leery as I've said throughout this whole course of just going out there and finding random stuff so let's go ahead and augment this for what we want it to do so we want the hogwarts.org we can leave that password that's fine group principles account management group principle okay so this is interesting it's actually using the new object command lights not using new ad user huh um let's go and change these houses too oh I don't know kind of want to give it a shot let's give it a save let's go ahead and give it a run see what it does dude all right funnily enough you know what I forgot to do it's not copy that oh no I did the whole thing yeah it never shows the form you kind of have to know that just name it form all right yep that script but if you didn't know that you needed to do uh show dialogue it wouldn't work um yeah oh I don't see our button create user button add click it's interesting all right what's different about my button over here do you have Windows that forms a button station it does do the size differently hmm let's see if we can't oh no no that's not even the issue hold on the control is never added you'll notice yeah never give us the uh the control needed to be added um that would make more sense why it's not visible not the other thing okay again knowing how the windows forms actually work all right run there's our create user button all right you can't add a Ron Weasley now actually two we're not I don't know where it's going to put it there's no path to find it's actually just using the command line I'm not really super familiar with anywhere puts Ron and uh we can go from there is out too is it created successfully okay cannot call method with a no valued expression or so it's not liking the user 65 obviously wouldn't save it and exception calling save with zero arguments okay all right so this is where I'm like all right this is kind of really working out for me this is where chat GPT gets kind of weird right so let's go back specify what commandlet we're using you type this piece of it all right we're going to specify the command that we want to use and look at it go there we go see it's kind of doing it more the way I was doing it earlier oh yeah I didn't break up my account password I guess I could have done that secure string thing like that path of U let's see it gives me my OU not made commandlet um right at the end okay that was Powershell again that's pretty cool now that said did makeup on weasel user I think well no actually I don't think it did because and complained about that at the end all right let's squeegee this I just want to start fresh and we will change our path does not set a user principal name hs3w students and I hope you feel like you're learning here still guys the reality of using chant GPT um yeah I'm gonna pop this out here I don't know what I was trying to do probably I would think an out file uh it does add the button this time and that may have just been a stopping where it didn't add this stuff no I'm thinking about it uh it's not a bit you know I'm wondering if I had the plus version of uh chat GPT if that would have worked we'll do a house dude they call it a house combo box I love that there are pluses in here all right I'm going to construct the user what he's doing a substring so I was doing first first initial last name it's not putting it to lower again I didn't tell it to I think it's pretty cool that it suspected that this was the way to do it um and this show message box is something I normally use too let's give it a run Okay cool so I made it about the same dimensions actually uh what did I try to do oh so it assumed I think we're good here those two that used a splat that's something we went over in unit two no unit one actually splatting um parameters in this format and then uh passed them to the commandlet that way but the issue is right here it assumed we had a group uh named after the combo box which would be fair to us soon right it's okay you're probably trying to add a group right so let's go ahead and see oh did not add onto Gryffindor they create run so let's see where it put him oh you know what did it gotta refresh classic ad lesson all right cool so it did set these uh values that said it was going to set oh didn't give him a login name oh it did for pre oh yeah see this is where it didn't set the user principal name which is something I called out um and then also I don't like that so let me do this to fix it there you go I don't know that the user principal name is actually set though oh it is okay all right yeah I mean I think that's pretty good I mean jeez so just by getting a little bit more specific with it and that's probably a good lesson just with using the chat GPT right the chat GPT um yeah you gotta just be specific uh and it's not something you would think right you wouldn't think it wouldn't use new ad user but it just didn't the first time but our second script down here it's pretty good to go so I mean it even did our Harry Potter examples named everything cleanly uh yeah gave us some messages didn't finish generating again which is why I think you need to upgrade to plus if you're using this a lot uh just to get those complete quality responses but yeah wow really good though for just writing code for free for you well I think that's about it for this lesson uh really good good time you know I could play with this all right I know other Powershell Engineers out there love doing this as well so play with this all day well thanks so much you guys we'll see you in the next unit
Info
Channel: PowerShell Engineer
Views: 9,560
Rating: undefined out of 5
Keywords: PowerShell
Id: 9oiEOYFe6PI
Channel Id: undefined
Length: 84min 59sec (5099 seconds)
Published: Fri Jul 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.