PowerShell : Automate the Admin - Matthew Dowst

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome everybody welcome to the new york city powershell meetup my name is doug fink and i'll be your host and tonight we're looking forward to automate the admin presented by matthew daust looks like it's going to be a really great topic before we do get started with that coming up for the next three months if you want you can in october we're going to have mike kanakos he's going to talk about powershell secrets and the power cell powershell secret module he's also the host and organizer of the raleigh powershell meetup group in november we're going to have friedrich wyman i don't know if you've seen his tools they're really interesting set of tools he's written for powershell over over the years and he's going to cover pipelines in a nutshell should be a fun topic as well and we're going to have the other in december we're going to have the other co-host co-organizer of the raleigh group uh phil bossman he's gonna talk about core concepts making sense of functions uh how to write your first function how to get into advanced functions uh should be another interesting topic so tonight really excited that uh matthew dallas is joining us and put the time in to put this presentation together um and tonight matthew is going to show us uh tips and tricks on how you can use powershell to free yourself from tedious administrative tasks something that powershell is really really great at um matthew's an automation consultant 15 years experience he's really involved with the powershell community he writes blogs he publishes the powershell weekly newsletter if you're on twitter you can see when he publishes that and he's author of practical automation with powershell and on that note um at the end of his presentation tonight uh we'll be asking you to drop your email into the into the chat and then we'll pick some lucky winner to win a free copy of his new book so without further ado matthew i'm gonna hand it over to you great thanks uh appreciates great info and so you guys have a bunch of uh really good stuff coming up so hopefully i can uh hold a candle too but uh i'm sure you will basically so tonight you know i i kind of like to go through you know as doug said kind of automate the you know the admin right you know there's that famous adage you know it says uh you know i'm sorry matthew you're sharing you're screaming i'm sorry yep that would help if i did that yep cool there we go [Music] all right i see your screen great so yeah as i'm saying there's there's the uh the age-old adage of you know always choose a lazy person to do a difficult job because they'll find an easy way to do it right you know so i am often that that lazy person or you know the person who just hates doing repetitive tasks um i've also found powershell to help me out with uh you know things that i just know i'm not very good at like organizing my inbox right uh and uh so it's kind of go through some some different you know things that i've done throughout the years uh i've put together this is you know this is all you know open uh environment you know no clickers or anything like that so feel free to ask questions or anything along the lines um but with that you know go ahead and get started uh so the first thing i was going to talk about is you know we've all had the uh the issue where you wake up in the morning and your inbox looks like this you just had something flicking on and off all night long right and you also kind of run into the problem of i don't want to create a rule right because i want this i you know i want these alerts to actually show up in you know on my phone and things you know when i'm not sitting here looking at my outlook but at the same time you know my my inbox ends up looking like this and i can't really find you know what what needs to go through there uh so you know what i did is i used powershell to help me solve this problem and uh walk through some of the ways that you can do that and so the way that we're gonna do it is actually through the outlook com objects so what this allows you to do is actually use the the apis in the back end and outlook to be able to perform something so you don't have to be an exchange administrator an office 365 administrator you know connecting out to the to the cloud or to your servers or anything this is just going to do everything right here you know through your local outlook client uh so you know to get started and we'll see here is you know you get the the fun little assembly path to add in and uh and then declaring the outlook application and setting the name space right those pretty much just standard you know telling powershell i'm using outlook here's here's the thing that you need uh and this this assembly here uh it's not required but it it will help you out tremendously right because you have these different enumeration lists here right so you know outlook folder inbox you know that maps back to some number i think it's one or zero you know it could be 14 i can't remember all those off the top of my head right so i'll just load that assembly in there and then i'll let powershell help me do the rest right so i can i just know that i need to get a folder there's all my different folders my inbox my contacts my calendars journal whatever folder i want to get you know it helps me out so don't be you know scared by that command it's not that bad you just kind of remember where it is and you know rerun it so what i'm going to do now is just go ahead and you know grab my inbox and then i'm going to create a a list here of all my inbox items so there's this when you generate this inbox or really when you do this on any outlet folder you'll have this property called items this items property does not populate by default when you do it it does doesn't populate until you specifically call it depending on the size of your inbox you know that could take some time you know it's 10 15 20 seconds sometimes to to populate that so i just use a quick for each to put that all into a list and then i can go down i can use this list over and over again right this is everything that's in my inbox so then you know entry powers felt powershell fashion you know you have all of your items right so you can do your get member and you can see you know where i have my two you have your subjects sender name sender address right so you can you can essentially just using aware object create a filter on anything you would like so i can take a look here i have a bunch of emails that you know i saw here coming from azure if i run that i could see you know got back the subject line of all of those now in this situation i was i was good when i created the alert in azure and you know put put a name in there all right so i can actually use a little bit of regex so this is uh you know just telling it to get everything that's in between uh square brackets right so you have your you know forward look up basically everything in between and then ending here so if i actually run this again see it extracts out that value in all of those uh you know i've done similar ones as well to where you know it gets the the name right and this is basically what i'm what i'm doing here is i'm i'm telling it you know where i want where i want this file to or where i want this email to go all right so if we look at my outlook here i have you know contoso folder and northwind's folder all right so let's just go ahead and get these filed away and then i can go through and deal with them right so in order to do that i need to be able to have the folders that exist in there right so again if i you know pull up my inbox folder look at my folders right so it's only going to give me the top level all right so i just create a simple function here basically for each folder return the folder if that folder has folders it's just going to recurse and i'll get all of my my folders here and then i can just match on names it makes it much easier on myself it does you know take a little bit to set up on here but then again you know we're going to say get our ones with this email address go ahead and extract that name out again just like we did right here but this one we're going to check and see if there's a folder that matches that extracted name all right if there is then we can just simply call a move on that on that object and i have it out my inbox for me so all of those got filed away into you know appropriate folders nice and and so basically in the first few minutes of your demo you're showing reg x's and recursive functions i like it go ahead it was fun so then again so so we can take this even further right let's go ahead and re-grab the inbox and then put this into a function as well right so again just the the mail item right the the folder that we wanted to go to and add an extra one in here for from mark as read right because i'm not going to go through and read all these i know there was a there was some alert that was flipping on and off all night i don't i don't need to do that right and then maybe even add a test parameter in here so that i can you know see what it's going to do before i do it right so when i'm using this on my actual work email i'm not accidentally overriding something so you know simply coming down in here and we get the object unread set it to false save it and then again that same method that move method all right so just to kind of show how you know figured all this out is uh you know you can go on my way now so i can go full screen there we go okay so you know the the the infamous get member pipe this shows you all the properties and all the methods that exist inside of the the object that you're looking at right so you know mark as task move reply you can you can reply through all these save send you know there's there's all sorts of different properties that you can you can update and then different methods that you can call so really it there was not much once i was able to figure out how to get the stuff from with inside my inbox then it just kind of becomes you know clicking through here and you know seeing you know okay i can filter on sender address i can you know filter on these different items right and i can even go in here and do do a group object on sender email address and help me get some statistics like okay i got i got 23 that are coming from this email address maybe i need to you know figure out some sort of way to to clean these up right just kind of a you know good way to help determine you know where things should go and then again so we can call our function and then this time when it runs it should so i have mark red set to true so now i go into my northwinds folder so oh sorry i'll put them in the azure folder so now i go to my azure folder there they are and they've all been marked red all right so this this is a just a quick little script i put together um uh i have another one actually that you can build in some custom json and pass it to it and it will handle a lot of that things for you so i've created some kind of filters and things like that and that'll be up on the uh the github at the uh at the end of this call cool so all your all the stuff from what we're seeing now will be up on github and i'll get that link from you later yep great thank you okay so the the next one we'll take a look at again using outlook right so the the same functions i have here again uh this time you know i i always get that emails like oh you know let me know what times you're free today or tomorrow or or what have you right and then i go and i look at my calendar and it looks like this and i'm sitting here trying to figure out okay this is a 15-minute meeting this is a it's just a pain right so i have this powershell script that just literally just sits open on my computer pretty much most of the day to be able to get that data right so again look you know very similar to what we did up here where we got the inbox this time i'm just going to get the folder so i get my calendar now where this gets a little trickier is i could do calendar folder dot item and it would return back every calendar item that i have uh but you know if anyone who's been at a job for a while you know you probably have quite a few items in your inbox and on top of that it gets really hairy when you start looking at recurring appointments because on the back end here a recurring appointment it doesn't actually show uh on the date of recurrence you only see the first one and then it calculates up all the different ones so it's really difficult to find out what you have going on that day right but there is a nifty little uh method in there called get calendar exporter right so you can get this calendar exporter here and load this into an object and i can see i can set a uh start date and end date and tell it you know use this method here i want to see my free busy again you know this is those fun little lists that we don't have to memorize but sometimes we do uh but then becomes the so then we want to you know now now that data has actually been loaded into here into this calendar share the problem is it's hard to view so if you look at the methods that it has it has forward as i count and then save as an ico neither one of those are really going to do me any good in powershell i want a powershell object that i can see i don't want to send an email to somebody or get that back but what i can do is actually when i do the forward as ical all right this actually formats it this creates the email but doesn't actually send it so it creates an email object in here and then again it produces the body and this is what the email would look like if you were to send it right it's going to say here's you know your free times your what all your different appointments are and everything listed in there people don't need to know all my other appointments right they just want to know when i'm free all right so we do a little more regex in here right so we have we'll go ahead and we'll split the body on on line breaks right so every time there's a line break in here we'll split and then when there's a tab the word free and free being the end of the sentence sorry you know that way you're ensuring that you're only getting ones that say free right if i didn't have this tab here in the front and something had free at the end like here this this uh run this here so we see this backlog view free came up right because so then i don't just want to tell it go ahead and uh do my tab because i know that's a tab character in there or you could do a space probably would do the same thing no this page doesn't work do the tab yep tab so now i now i have just my free times and again we can we can then take that uh a step deeper right so so each one of these lines i only need to get this first half right i don't again this this is a bunch of junk blank white space that that we don't need so again we'll do a split split on the on the tab tell it to give me the first one and we'll just you know just to be safe go ahead and throw a trim there on the end and there we go that's now i can i can copy and paste this probably not going to tell them i'm free before 8 am but you know i copy and paste this into an email and shoot that over to them and they can you know then decide what it is and you can set up any date time ranges that you want you know in here and have it uh generate that that data so just you know taking the body you know extracting out the data that you want and then cleaning it up a little bit with just a you know a couple little splits and and some and some matching and you're good to go good stuff so i don't think i've ever used the uh com the object model that way against outlook that's uh cool all right do we have any questions or anything before we go on or no questions yet people think it's pretty slick all right cool good deal good deal all right so so the next one i got maybe i do have one question so you're doing you're doing the right host um i guess would have been cool to put it in an object so you could do it to other things but that's just another step you can take rather than just writing doing a write host you can capture that and put it in a bs object or something like that yep exactly i actually have a another one that i use when i have to fill out my time card it splits it splits these out and then calculates the time between them oh very good okay so yeah a lot of things you can do with this very nice okay all right so so the next one uh it's it's it's similar but we're actually going to be using word to help me in powershell so uh i i'm i'm a notoriously bad speller just i just am i always have been i've i've learned to live with it in my life i've learned to adapt to it with my in my life and you know thank goodness that spell checker has gotten so good uh you know i don't quite run into the you know it doesn't know what i'm trying to spell anymore uh type of things but you can actually load that dictionary into powershell and then use that for other things right i initially wrote this functionality for system center service manager when i was working in that environment a lot to check my lists that you create your drop downs and things because there's no way to check your xml as you're typing it right so this is actually export out and one that would export out the management packs and then check the values inside of there just to make sure i didn't have any typos or anything that was you know looking horrible to the end users so again um you know we're gonna go ahead and just create a dictionary object again just like with outlook we'll load in the word application uh and then to actually use so to use the spell checker you don't need to have a document open but in order to get the suggestions you do but if we just open a document to void it's not it's not even going to open word it just essentially loads a word document into the background that my session can then use right the trick now becomes picking your language right so if you look at the available languages in word there's quite a bit yeah then trying to figure out which one is which and what what's select uh the get culture commandlet which is which is native powershell lets you know what your local id is right so i can say get my local id 1033 which is u.s english which will allow me to select just that language and then load the active spelling dictionary into this dictionary object all right now i can now i have this dictionary object loaded here that i can start using to actually spell check my words right so one that i notoriously misspell and to this day i don't know which one's either eyes or anything the word definitely i just i don't know one of these days i'll figure it out all right so then uh i'm doing here is you know using the word application text is just this is the word that i want to spell check if you have a custom dictionary so you've added custom things in there things like that you can load that in at the same time or you can just set it to null you can tell whether or not you want to ignore uppercase and then give it the dictionary that you want to check against and you came back and told me it was false that tells me that the word is misspelled all right but that false doesn't really do me any good i could sit here and try to figure out how to respel it still wrong right so the next step is to get spelling suggestions all right so again i have my word app get my spelling suggestions off of this word here it comes back here's probably how i should spell it load that back into here comes back true tells me that my my word is spelled correctly so how can i use this to help me you know with my powershell right so comments right i'm you know misspellings and comments are pretty common you know i also use something similar for when i'm checking markdown all right so you know markdown you can't really write that in word you're not going to get spelling checks and things like that when you're writing a readme and copying back and forth it just kind of becomes a pain right so you can use similar tactics on on other things but all i'm going to do right now is get this next script that we're going to go through and i'm going to load that into powershell just as you know get content which makes it a string object now if you're not familiar with this powershell has it has its own parser right so you ever wonder how ise or uh vs code knows what you're typing is a commandlet and what's a string and all of that is is this ps parser in here so you can actually take this and tokenize your script so if i run it on just everything you can come back and you can see all right command new line you know group end string variable operator it's it's pretty cool it's it's a really good way to you know check your scripts to be able to get data out of them you know i've i've used it to you know go through and read my scripts to ensure that i have all the right function or all the right modules declared in it and things like that but what i'm going to do here is i'm just going to go ahead and get my comments all right so if i look through here i now now it should just be what all my different comments are and it knows single line comments and you know multi-line comments and everything it's it's it's pretty good so essentially what i'll do now is just you know say hey every comment go ahead and run through you know the dictionary so the the comment content all right i know for a fact i have a misspelling in here so i'm just going to go ahead and break on it all right so here we go i i had a comment that i haven't misspelling it but the uh issue here so if i if i try to get the spelling suggestions on this so if i look at the content here right it's the whole line that it's given it knows it's when this check spelling runs it knows that something in that line is misspelled they get spelling suggestions can't figure that out it doesn't know which word i'm talking because you notice it's not loading a dictionary or anything else into there so to get around that we can again create a create a function where what we'll do is we'll get that comma the comment content let's say that three times fast uh and and split it right so just a regular split with nothing in the middle is going to cause it to split on uh on spaces line breaks tabs anything along those lines all right so then i can individually check each word inside of there right and then even better thing about this comic con it tells me what line it's on so you know i can come in here uh i now know this is on line 24 right now i'm gonna get so i'm gonna get my spelling suggestions on that particular word i'm going to go ahead and just throw them all into a ps object and and let it run so if i come in here spell check my comments and then i run through each comment it's gonna come back hey line 24 this word is misspelled here's some suggested you know replacements for it so i can go in over here and fix my word and then if i run it again just order everything comes back clear and good so using uh the dictionary in there to be able to you know spell check something that's not necessarily in word uh it works pretty well you know just remembering if you want to use the spelling suggestions you know it's it it goes on a per word basis right so depending on the logic that you want to do you know you could have it code check the line and then if it comes back that's false then break it up into the individual words and have it go through there it's you know again kind of possibilities are are endless on that that's really slick so you and i share the same problem i can't spell either and uh i tell people you got you can i can either do powershell coding for you or i can spell in my documents which one you want me to do so cool this is a good way to automate that process i like it so uh on time okay no questions no questions yet in the chat so let's keep going cool uh so this next one this so the ps notes this is a it's a module that i wrote uh that's it's out there on the powershell gallery and github uh and what this is is those commandlets that you just hate typing all the time right uh like arrays you know i hate typing that the only reason that got in there so fast is because i have a mechanical keyboard i have program i have a gaming keyboard that i use to program macros to type my powershell for me all right this you know but i don't always have this particular keyboard with me in things right so i created this ps notes module which will allow you to define different snippets and then just call them with a with a simple uh alias here so stopwatch all right so i got my you know start a new stopwatch stop it you know kind of get you know the elapsed seconds just kind of a quick and easy way to keep track of those things right so you know it has some built-in search functionality in it so i can say you know i need that have been tagged as file right return those to me so i can see here okay here's my one for removing a file here's my one for getting a file name without the extension in it you know here's one for creating a new folder you know just those it kind of came out because i had a onenote that was just full of different little snippets that i always copied back and forth all the time right and then it even you know has a out grid view if you want to grab that so it imports that in you can use that and then we'll kind of see here you know you can create your own custom notes right so again gotta get a remote registry key and it's something i you know have to do quite often i don't really don't feel like remembering typing this out all the all the time so again you know i can create a note for it right so i just give it a name alias you know details you can tags so the tags are is an array so you can assign multiple tags to it and then uh this is functionality so if anybody's already familiar with this that has used it this action that just i just added this functionality in this is the default action that it's going to take so you can have it display you can have it copied to your clipboard or you can have it run it which uh kind of comes in handy right so again you know we can look at the one that we just created there it is i can copy and paste that put it into my script that i'm writing it works it's it's not something that i i would put in like i'm not going to put this bridge here into my script right it's going to be something that i go here and i'm going to copy out and put in there but at the same time i can use it to save myself some time right so i created this one azcon there's about five or six different azure subscriptions that i need to connect to on a daily basis all right some are in the same tenants some are in different tenants things like that i created this this one here just as a simple uh you know read host says which which subscription do you want to connect it let's connect to this one so that one's set to where it runs uh by default right so if i show you what uh what this one actually looks like all right so i just created a uh an array here of all the different subscription ids that i would need and obviously i have it blanked out because we're on a recording uh and then you know it's just you know list those out for me that's what you saw right there with the you know the one two three four all right and then and then a read host then that read host is gonna take that thing it's going to check and see if i'm already connected to that subscription if not it's going to try to switch me to it if that fails then it's going to clear the context and then ask me to sign in again all right just a quick easy way when i'm working i'm switching back and forth between environments i want to you know be able to just connect to these different ones i just type in daisycon and i'm i'm good to go cool so a couple of questions um i think yeah for me you answered one of them but somebody's asking about the pros and cons of this uh versus using the visual studio code snippets natively yeah so that's a great question so uh the nice thing about this is it saves it as a json file and this gets written into the app data but you can create multiples of these and actually import them in right so you can share them amongst your team uh you can transfer them to different you know devices you know a lot simpler plus this works in uh powershell seven and five one right so yeah there are some things just you know still have to hit five one on and you know so uh you can ex so there's a functionality to export these out it'll export in a nice transportable json that you can then you know share with your team put it on a network share let everybody get access to it yeah the goal seems to work pretty well yeah so i added yeah it works across a whole bunch of different features things not just limited or just uh constrained into the visual studio code session exactly cool so got another question how about adding or words uh adding more words to the dictionary or excluding words that are detected as misspelled so i guess going back to the word uh the spelling that you were doing yeah so so you mentioned you can create a custom dictionary object and then you would load that in i don't have a custom dictionary on this uh on this computer i just just rebuilt my my home machine uh but essentially just the same way that i grabbed the dictionary here you can grab your uh your custom dictionary and import that in here where i just had null sounds good and of course people want to know they like your font and color skinny theme um what are they what's your color scheme that you're using in the fonts this is just the uh visual studio dark default cool so the standard dark theme and you're good to go awesome all right uh no more questions yet so let's keep going all right so uh this next one uh selenium uh for those that you uh that aren't familiar with selenium it is it's a web application testing tool right it's used by a lot of developers uh that create web apps to you know do click-throughs and things like that once they make changes to confirm that things are working well uh my company has notoriously bad forms to fill out not nothing against my company at all but you know and i'm sure everybody's company has the that sharepoint form that's just been used forever you know every time i need to make a travel request i gotta retype in my driver's license and all the other you know my frequent flyer codes and everything like that uh so you can use selenium to actually perform actions inside of a web browser for you right so this this selenium model it's uh it's made by adam driscoll he does a great job of keeping it up to date and getting the latest drivers into it and things i've just personally found that it just works better with firefox edge and chrome change their drivers so often it can get kind of buggy like i said adam does a great job of keeping it up to date but i mean chrome can update in the middle of the day sometimes so if it's not the exact right version it gets finicky right so so chrome and edge they work but you know i've found for for these purposes that uh that firefox works pretty pretty well so if i just run this start sc firefox it just pops pops open a firefox window for me all right then i tell it to enter this url actually yeah i'll hit me for this but uh i'm sorry this one works better in five one it's just it's it's faster if i wanted it works it works in seven um i i don't know what it is i haven't bugged uh adam to ask him why but it's a lot faster if i want so for demo purposes we'll use five one all right so so now i have my form loaded right if you notice here this driver this is this is what's telling it you know this firefox session that i have going on here and then you have this get se element it's a selenium element so that's an element that is inside of this form right depending on how the form is created some of them are great and they have an id or a name or something like that but uh in this example i'm using a google form which doesn't so if i come in here and i do an inspect on this you know on this box here i see that it has a class it has a object as a type you know there's no id to it right it makes it kind of difficult for me to say you know get sc element by id and give it an id forms like that just this works great on forms that don't you can still work through it by using the the console debugger here i'm just going to right click copy copy my xpath which i already have pasted in here but show you that is a ridiculous path that you're you know never going to remember you know you don't have to sit here and go you know div div div and figure it out it does it for you all right so now i can come in here and say get this element this this text box so i can come in here and i can see that it's i just grabbed it and then this s e send keys there it goes it sent those keys into that box so it actually uses the send key and not programmatically doing it so you know because you can use like a you know a web request to fill in forms and things like that this is actually how you know how somebody would sit here and go through it so you're not limited by the back end of the form right you can essentially get it any way you want all right so if i go through and i you know click on my three text boxes in here and i can then you know copy the x path on each of them make a quick little function it says get my text box throw my my keys in there right so run this all right so filled in all the all the fields that i wanted and i'm not i'm not a nihilist for those who don't know arthur dent is uh from hitchhiker's guide and the world was ending when he left so uh the next part then becomes you know these radio buttons right so i could do the same thing here on these radio buttons you know inspect it get the x path to it uh but that gets kind of tricky right those those can change you know if they added a new selection in there things like that it's kind of hard to to be able to to do that but if i look at the class that they belong to right it's this uh radio group container right so this uh export outer circle right here did you get to the right this is a lot of times this takes a little bit of you know finagling make sure you get the right one you know you can just kind of test the different ones but again i can go ahead and say okay anything with the class of export outer circle all right and then if i return that i got back quite a few and it looked like they're about the same as on here but unfortunately i don't have any text to go with them right this i got these locations uh try to bring that but you know let me just go ahead and test it out yeah zero is is you know the first one one is the second two is the third so it's it's you know pretty safe bet and if i look at the uh location on them i can see that they all go down in a row all right so let's take it up a level all right so let's go ahead and find you know where these are if i come back up into here there should be a container that contains both of them so so my docs shared wiz toggle label container run that hey look at that there's there's my text okay so well i got so that's my selectors i got 12 of those radio buttons i got 12 of those it's pretty safe bet that they are they coincide with each other even though if you'll notice you can't always go based on the location because it won't always be exactly the same you see these are about two off and they're not even they don't even line up perfectly right so but if i if i just go ahead and take a look here label right so this selector is i have you know all my text fields and this is this is an array so i can use index of so index of full day is number two okay i run that in here just up here see it not too bad all right so so i've pretty much been able to kind of determine yeah those those coincide with each other all right so again i can create a function get my selectors find the index of my label use that label to push that button alright so if i then come in here run this i just i've just selected all my buttons all right and then then one last final step in here is again yeah you can just come in here inspect find out what the class is what the label is what the you can you can go based up you can do the css you can do class you can do uh xpath there's ids names you know just depends on how the how the page is formed to get that data in there so i can go ahead and get my submit button sure that i got it and then there's a send click request has been submitted right so i can fill out these forms i can get you know all that data that i got to put in there over and over and over again all right uh yeah another great use case for this is the microsoft catalog the uh the updates catalog which is has a horrible back end and there's no way to be able to get the data off of that right you can you can have it go out search the catalog come back get all the results for you and you know that you can then load that data and you know audit it against whatever you need to do uh and then of course always just ending your session to clear it out and close it there are other tools out there as well that you can that you can use with it there's this selenium ide here right that'll allow you to put in a url and it'll start recording and you can do all of your your your click-throughs and it's recording this as i do this and then i can come in here and i can see okay i i opened it up i did this i clicked here on this css target right so i copy that and i click here on this cs so you can see you know how you can translate this directly over into these commands here right just depends on how you want to go about doing it this works really great if you have a a page that changes a lot you know because and then this is not something that i would i would use to replace like a robotic process automation this is something that i you know i kind of use on my own right it's uh it's it's it's a test environment it's not really a robotic test it's not really any robotic process automation that's pretty cool so css html web pages all glued together with powershell nice i see the the question in there about uh sso uh auto login so yeah you can have it fill out uh logins for you uh you can define profiles so you just point it to you know you a lot of times what i just do is i'll you know go and log in say remember me and then close it and let it uh open it up and do its thing or you can have it actually fill out the forms for you uh i have i have one that does some twitter scraping for me because twitter does not has not exposed bookmarks to the api so it just opens up twitter puts in my username password sends my phone a mfa request i reprove it and then it goes through and does its thing to pull the information for me so you can you can either pre-stage it or have it do it obviously it's a lot more secure to pre-stage it unless you attend the next meeting and learn how to use the secret my management module and have it pull your credentials from there all right so uh one last final one uh wanted to show through and talk to you guys on is this uh server setup script here i have here i said this is one that i use because you know i'm always creating new vms and blowing them up and yeah i want to be able to test things in certain conditions and all those other things so create this script and you know for some versions of uh of it i have can get pretty long 143 this is not too bad there's some that i have that are a couple hundred that will actually go through and create sql databases and you know upload data for me and things like that um the really cool thing about about these and the way that you can do it is uh through github gists if you're not familiar with these these are uh so it's not a full-fledged project it is just a a single script that you can upload uh to your your guest and you can make them private or public so this one i have you know here's is marked a secret so it's if you go and look at my profile not logged in as me you won't be able to see this but anybody can access it uh via the url right so i can get this url to this script here and then i can go on to my brand new server that just has a couple things installed on there open up powershell five one use the invoke rest method so basically an invoke rest method is just going to grab the raw text that is here on this screen and then invoke expressions just gonna execute just like if i had copied and pasted that entire powershell script onto this machine you know you can even use a shortened url on here if you want because you know a lot of times it's easier to copy a single command like this and it is to copy an entire thing right so it's going to go through it's going to install powershell 7 it's going to install chocolaty then you know that's gonna go through and it's gonna install uh vs code i have it uh so it goes vs code it it installs the extensions that i like it to install that i always want to have on there you know you can even download your your workspace file and to have all your settings and everything automatically moved over uh and then it starts go goes through and starts installing some powershell modules right so essentially you know using chocolaty is is really kind of the best way to to get that right but just to start with you know installing powershell seven and it just you know just look familiar this is pretty much exactly what we just used to to kick it off on that server there uh except for yeah this is a an official link from microsoft that you know installs the latest version of powershell 7 for you all right so you see here we're doing our import excel module thank you yes trust me i that one gets installed everywhere i go that's not pandering cool uh but it also will check and see okay are you are you already running powershell seven because if so i'm i'm done you know i don't need to do anything right if it's you know if it's not running powershell seven it's gonna go through it's all just gonna do is just check come up in here and see if it's installed so just checking the uninstall uh you know in the local machine and the current user see if the uh url for powershell is put in there uh actually you know take that back that's for chocolaty cmi cim instance will tell you if powershell 7 is installed or not chocolaty we can go through and check the uh install here so it goes through tests the this version here all right if it doesn't exist it errors out i know i don't have anything and just returns blank all right so then i can go i'll just go ahead you know go ahead and install that they you know again pretty common one throughout the community now you see that it just kind of starts running through uh you know checks again reloads environmental variables checks again make sure that's installed if it is then it continues on then i got the one where i checked the url all right so checking for git let's get installed go ahead and install it right is vs code installed if not install it right and then getting the code extensions you know invoke expression code you know this this just is a listing of the ones that i always use and then here is where it gets a little you know trickier for lack of error because if you noticed here i'm running in five one right but i want these power shell modules to be installed in seven so actually what this is doing here is creating a string right so if i here and this is this is just a you know simple get module list available it sees as if it's there if it's not you know go ahead and set the ps gallery to trusted install the module uh otherwise you know confirm that it's already been installed and move on to the next one right so then what i can do here is i can i can bundle this all into a single command all right so i have my string here you notice these curly brackets zeros those get replaced by anything after the format so now my command has my module name imported into it over and over again right and then again i'm just going to create a argument of command run this command and i'm just going to call pwsh which is your powershell 7. so it's actually going to launch a second window to go through and actually if i re run this it'll go through quick because it actually does it checks every time right to see if everything's on there so you see it's popping open a separate powershell 7 window to install those modules for me so that they are in the you know installed in the version that i want them to be installed it if you see here i now have git vs code powershell 7 and everything just got installed for me so these are these are pretty nifty uh one word of warning on them if you edit them it changes the url so anytime you make a change to it you need to make sure if you you know have that url saved off somewhere to to be able to call a script like this uh just you know make sure that you update that big old long alphanumeric it's not even a keyword on a big big ugly string so that's definitely one thing i wish they had did not do or make it so you say every time i edit it don't change it yeah so there's another question i think in the uh chat yeah yeah so yeah there's yeah there's no reason you couldn't uh install them straight in powershell uh the reason behind well i wrote that on in in there like that was when i was testing different version modules between different you know instances of powershell and you know trying to keep them separated but if you you know let it auto discover in in both paths then then you can certainly just install them in in the one and let them go and you can you know update that to include version numbers or anything that you want in there you know however you build that command out in here right would be how it installs nice hey i don't mean to call you out but i am i think did you miss an l in your in your test installed by from url so yeah i might be wrong so if you scroll back up there we go yeah yep see if i told you i'm a bad speller that's the theme of the night so so my next blog post will be on how to use the spell checker dude check the spelling of your function names hey you know that's uh i do it all the time and then it's like by the time i'm halfway through building things and making tons of dependencies it's like i don't think i go back and renaming everything so forget it yep awesome a few of those that haunt me [Music] so uh all of these uh are available out on uh like github so uh i'll put paste that into the chat window great and i'll put that up on the link later as well thank you so uh i do so the downside to detecting chocolaty via the environmental variables uh the the reason that i had it run that way is because after chocolate installs you actually have to close and relaunch in order for it to uh get the environmental variables so this kind of prevents you know and you know you not having the environmental variable in there right so if it if it ran and got like halfway through or something like that you'd be able to kind of restart without having to close and reopen your session nice makes sense all of your examples have been great and timely in the chat awesome any uh so is that uh wrapping up your that's it that's that's that's great that was that was perfect um so any questions in the chat um because what i want to do this has been been great yes it has been great thank you matthew it's been awesome um so what i'm going to do is i'm going to turn off the recording and then we'll do a little bit more business so everybody wants to please stay on if and i'm going to stop the recording okay yeah and so in the spell check i did not have the office path
Info
Channel: Doug Finke
Views: 867
Rating: 5 out of 5
Keywords:
Id: LpxALsotCPQ
Channel Id: undefined
Length: 62min 7sec (3727 seconds)
Published: Fri Sep 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.