Microsoft PowerShell for Beginners - Video 1 Learn PowerShell

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is Shan Yong with bold zebras those guys and today we're going to start off our powershell series so this will be video one in a several part series it's going to go through everything from basics of PowerShell to how to do some really awesome stuff in PowerShell all in pretty short amount of time because let's face it you don't want to watch your long videos on PowerShell so this first video we're going to kind of cover the basics so things like you know variables and aliases and get commands get help you know just try this for that core stuff that if you're just totally new to power showing like how do I even get started this is the video for you video two is going to be how to deal with objects so one of the great things about PowerShell is instead of like the command prompt where we just get a bunch of text back powershell we get a bunch of objects back and so we need to learn how to manipulate those so select those and sort those and where and for each objects you know lots of different commands so we're going to take a really gnarly script that I'll show you the end of this video and work through that and figure out how to make all those fun things happen for you in video 3 we're going to just talk about some of the other Commandments that I think you should know so maybe some more refinement of the object work may be things like what if different parameters just some core tenets of PowerShell that while you can probably get by in PowerShell without knowing a lot of those there's going to be kind of a bunch of here's random stuff that make your life easier if you embrace it video 4 will be all about sharepoint so using SharePoint and PowerShell so we kind of like the first three videos but just putting the context of sharepoint I realize that a lot of my audience really just wants to learn PowerShell from the sharepoint point of view reason teaching the video series is all up till is because I really feel like you need to embrace PowerShell not only for sharepoint but for things like asher and AD and even manipulating your own desktop so speaking of Azure video 5 will be all about Azure PowerShell so how to get that installed on your machine right you have to go out and install it and update some things and then once you get that install we need to be able to connect to it and then kind of manipulate the different Azure objects so I use my Azure scripts to start on my VMs or turn off all my VM you know there's other ways to do it but those are just good beginning tasks because it's something you can accomplish and see accomplished using a PowerShell so that'll be video 5 and then after that video 6 to infinity those are just going to be based on questions I get from you whether that's on Twitter or if you leave comments down below you know if you have more questions you're confused you just want to see me go deep on a specific subject just you know those would be random videos so alright so to get started here we're on my Windows 10 anniversary updated PC but you could definitely be you know on your servers or any of those type of voices right PowerShell transcends for quite a bit of time now so all right the first thing we do is I make my start button and then I'm going to start typing in PowerShell and you'll see that you get a lot of different options and so predominantly what we're going to start with this for this video is we're going to do the Windows PowerShell so this is the regular desktop app you could use the integrated scripting environment the ISE and the x86 the old 32-bit stuff we're not a mess for you that but right now we're going to ignore the ISC I like to start with just the point will prompt some right click here and we'll say run as administrator now you always want to run power shells oh I get a little pop up here so yes you always want to run PowerShell as an administrator just because it lets you do everything right it's nothing more frustrating you're kind of working through problems like what is going on one will this work one will that work and you realize it's because you didn't have enough access to the specific object you're trying to manipulate with there's probably some reason in the world not to run PowerShell as administrator I haven't found it yet so I pretty much always run it as administrator and Before we jump in start typing and making magic happen here what I want you to do is I want you to right click up here and then do properties and so here this lets you set some of the different properties for this particular console so cursor sighs how much buffer you want to keep a couple things you want to check on that you want to make sure you have quick edit mode check turn turned on that allows you to highlight the text copy and paste that type of stuff so windows 10 I think it's turned on by default but some of the older it's not so you want to check that on yours and then if we go over here to font I always like to kind of adjust this to make it as readable as possible so I've went ahead and bump mine up to 24 so that way it's a nice big font so hopefully it translates pretty well for you guys on YouTube but find the kind of setting that works the best for you and then I'm also no mess for the layout I also usually like to change all the colors to something cool I usually go with a black and a neon green this color you know give me a little a s400 hacker type of hiding in my closet type of feel but for today we're just go ahead and leave it on the default setting so I'm gonna say okay so that gets our console window set up if you're changing the settings yours might have resized nothing too big of a deal so the first thing I want you to type is start - transcript and so you notice I stopped typing portion way through there right one of the great things about PowerShell is you can use tab complete so i typed in start - transit hit tab you get the transcript finished and i'ma press ENTER now that went ahead and start us the transcripts it's gonna keep a running log of everything that we do in this session and we're actually talking about that a little more towards into the video once we've already done that but start transcript is a great thing especially when you're learning and really forever to always be the first thing you type in because there's nothing more frustrating I've experienced it a hundred times become a dummy is solving a problem in PowerShell working through how to write that script to do the thing that you want to do and then closing PowerShell and realizing it's just gone right there's no history this by default unless you do a start - transcript and so now everything that we do in this session everything we type in everything is displayed on the screen will show up in our transcript file so very helpful for us okay so we got the little blinky cursor here so the first thing I always like to type when I'm trying to learn what's going on here is I'm going to type in get - column tab to autocomplete get - command press enter and so this is going to scroll for a minute here it's going to show us everything that's available to us in PowerShell all the different command line although functions if you will that we can run in this particular console section so session not sectioned and so what this does is this gives us an idea of all the options I'm actually tired at scroll if someone hit ctrl C that just tells it to stop doing what it's doing so that's everything you're more than welcome to take that it ready to be all written in the transcript file and read through all those if you wanted but that's a lot so one of the things we want to do is we want to take advantage of the fact that PowerShell has a set of rules and this one set of rule says is everything has to be in the form of verb - noun or action slash object right so we type didn't get - command right we can see that get is our verb then - now is command so get command is a proper powershell commandlets and it's in that format so knowing that we have that format what I want to do now is I'm say get command I'm going to - noun so right the thing that's on the right side of the - and I want to return all of the ones maybe I want to return anything it starts with s and then a star so this is just all of the commandlets that are have a noun that is s and then star so it kind of lets us filter out a little bit more that's still pretty overwhelming so let's try something a little more specific so I see that there's a service something so it doesn't do a get - command and then - noun service hey that's kind of helpful right so this command I get command we gave it the parameter of - noun and we said for the value 4 that is service so it just returned eight objects here and that is the eight different command lights that are available for manipulating or working with a service so we can get a service new service restart service resume blah blah blah blah so this is one of those great things about PowerShell sooner you understand it the better but because Microsoft enforces a set of rules that verbs have to be specific ones right they can't just create verbs on there they have to use a core set that the Microsoft PowerShell team specifies it makes learning powershell a lot easier right you're going to find that you're almost exclusively you always start with yet and you just be used to the fact that there's a get command for just about everything so knowing that then we can look at the downside and so once we found that the noun for service we know that here's all the different things that I can do to that particular object so for services I can get them like a new home I can restart on etc etc so let's try one of these commands and so what I would do here is I would say get - command I will try wait and say that say get - service and just a dinner and after a little bit of scrolling there you can see that it actually listed all the different services let's scroll back up real quick okay so we listed out the name of all the services so the internal name the display name and then their current status that's pretty cool so that gives us some good information back and it's unlike the command prompt which we've used for so many years where we just got back to screen dumpling text these are actually objects this is the whole object for that service so the alljoyn router service have no idea that is that object was returned and it has a status a stop but we can actually go manipulate that to a particular object so let's scroll the bottom here again so we found get service it lists all the commands but I'm now interested in what all can get service do for me so what I'm going to do is I'm going to teach you another command it's called get - help as well as score once and then once I get - help get - service I can hit tab to complete as well and if we hit enter ah there you go it says hey I'm happy to offer you the help it's here but I know it's been a while since you've updated the help system you want me to go out to the internet and get the latest version of the PowerShell help absolutely so I'm gonna say yes and hit enter and so now it's going out it's hitting those out Weather Service's Microsoft makes available and if it finds updated help files it's going to start spinning through those we're going to wait just patiently just for a second okay so you see it's starting so I'm actually going to pause the video while these process and then we'll come back when it finishes okay so that took about two minutes or so when you see a sheet finish it actually just dumped out all of the help so let's type it in again so we can see a little cleaner here so now I could type all this out again or we'll backspace and if we press the UP button that gives us the last command that we ran in history so okay so this will show you a get serviced gets the services on a local or remote computer good to know we'll cover that in later videos how to deal with remote sources and it gives you some kind of syntax e self description it says here's the other related pieces but down here has a much better advice as you know if you really wanted to do this what you might want to try is hit the up arrow and then type - examples at the end so one of the rules of PowerShell this guy's got 11 examples is that every powershell command has to have help and the help always has to have examples so when you find a new command what you're interested in it's almost easiest to always just get help the command lit and then - examples so you can jump in here and start figuring out what what it can do or not do now I will warn you though that we found that you know says they have to have examples but they don't have to be right they are just typed in by a human being so sometimes you find typos and the examples and stuff just power through it and kind of use your brain like you see you know it says also says get - services you know that's probably just a typo and you should just fix that but so this will give you examples of different ways to work through using get service and some of the options available - so that's pretty neat scroll the bottom again so the next thing you can also do Oh we're do getting services is instead of - examples which you can do - online and so when we do this what's going to happen is it's actually going to take us to a Internet Explorer's to take us off the internet into TechNet and it's going to say here's all the stuff about that particular commandment and so this is going to have of the syntax detailed the parameters there's different parameters that are involved with PowerShell I'll write those at that - noun that we did our way fright for example all right that was a parameter so when you start doing more advanced stuff sometime detroy help for coming here and look at parameters and say hey what type of input does it accept can I use wildcards you know if it uses true/false which are the types of true/false is at use there's a lot of that little stuff that can be learned from this as you go along but yeah so here's all the parameters an update on all of them some notes and then all of our examples again so another great place this gives you a chance to read without having to you know look at that tiny little blinking phone especially get that black and green screen or something on so I'll minimize Internet Explorer for the moment okay so that gets us through getting some help off of this particular command so let's clear off our screen so I'm type in CLS now you notice I just typed in CLS right hit the up to show you but that's not in the form of verb - now so what that is is that is actually called an alias so to make powershell easier Microsoft allows you to use aliases and they have aliases for some of the different common things that we're used to right so cos or you know if I wanted to back up a directory and I can doll CD backslash now aliases though they can be a little confusing so what I always recommend when you're learning PowerShell is to never use aliases and to always translate them so if somebody should like me shows you CLS don't accept it just say all right how do I figure that out is what you want to do is you wanna use a command called get - alias and you type in CLS and it's going to say that CLS is actually clear - host right clear being the verb and host being the object which is the console window that we're operating in here so anytime you see something you don't understand it's not in the right form I always want to use get alias you can also just type in get alias whoa there's a whole bunch of them but it's going to give you all of the different aliases that this particular knows about so if you can go through um you know if we scroll like scroll up here real quick and so for example dir is get child items so now I know if I'm trying to kind of deal with folders instruct such child items probably what I want to do or we know we did clear host and so that was CLS you also notice that while they have all of the command prompt ones they also have a lot of the UNIX ones so like it right in UNIX you can do a LS in place of a dir idea dir in Windows and LS in UNIX meaning roughly the same thing so they both map to get child item man is the help system in UNIX that is maps to help so that's a very important step when getting started I was one of the things that really overwhelmed me when I was trying to get going with this if people send me these giant scripts so he run this and they'd use all these aliases all shorthand I couldn't translate what any of it meant and so once I learned to get get alias I'd take their script I translate everything and then when it's all on that verb - now for them it's a lot easier to consume so get alias is a very important commandment for you guys to be familiar with all right some equipment screen again and so that now that we know that one what I want to do is I want to show you another powershell commandlets not that not that this is one that is part of learning a core but this will give us a chance to play with some things so if we do get - process alright that is the powershell command with the essentially does the same thing that task manager does right it shows us all the running processes the handles the workers how many CPUs it's doing its IDs etc etc so that's a nice one and what we're going to do is we want to get a specific process so good old Microsoft edge right we turn on edge when you open up the prompt there so what we can do is we can type in get when I get command get process alright space then hit - and then we can do it by - name and so we could do Microsoft edge jobs a little tab complete that as well because power be pretty smart and so that would return just that particular process for us and you see it still edges still running down here so with that what you might want to look at is you want to be like hey I'm interested in what's there right can I keep telling you guys this is an object I keep just showing you text like you're used to so hit up and then we're going to take that and we're going to pipe it and so this little vertical pipe right kind of above your Enter key on most keyboards that is says hey take the output of this commandment and send its object or objects over to the other side all right so this is where we really started to get away from the old dos prompt and so here I want to do is I'm going to say I want to take that I want to pipe that over to get member and so let's scroll to the top again so get - member this is another one of those key powershell command what you do need to learn right we don't care about get process we care about get member and so get member shows you all of the properties and all of the methods associated with specific object so in this case our object type alright so system Diagnostics is the process object type and so if you scroll through this list you can see that there's all these methods so all the things that you can do you know methods are actions alright so we always use the car analogy so car dot start car dot stop car dot you know open the door right different things that you can do to the object so that's what a method is and then we have properties and so properties are going to be a just out of property of the car so car dot color is red car dot number of doors is for car dot make is you know Pontiac whatever you might want to do there how do you know do make Pontiacs anymore might be going back in the history books anyway so properties are the things that we know about a particular object so method right you can kill an object so you can kill that particular object you could kill the process of Microsoft edge good you know how people ready to kill Microsoft edge permanently um properties you know maybe you need to know what machine name is running on or um let's see what's another interesting one here how much CPU is it using what's its working set from memory that type of stuff so the different properties about that object so when you look at those one of the things I liked is so that's a way for me to discover right when I start trying to dig in this is getting us start to get us down that road a little more advanced but starting to understand that you can manipulate those objects and work with them takes you down the road so if we do this so instead of get remember this time what I'm going to do is I'm going to say select I know I'm cheating this is going to be what the next class is mostly about but select object star and that's going to return all of the properties about this guy and their value so his name is Microsoft edge you know as file a priorities normal how much CPU times you use etc etc what's his real name this gives you all that different information and so while this isn't really interesting for a process per se but we get into like share point later and we do this for a site collection we can see users and webs and lists and all that fun stuff or we do it for a sure we can look at a VM and then see you know what are the different properties of that VM and how might we manipulate does what size was it built with what process or you know what type of stuff so it's very important to understand that this concept of getting the member right showing you all the different things you can do with it and then selecting the objects and then finding the values you know for example PowerShell there's PowerShell out there you can change the master page of your sharepoint site collection by coming in here and editing the property pretty cool stuff just takes a little digging in pokken i'll type it and see us again and so that's one of the interesting things is once you understand that PowerShell is more than just like the command prompt that we're used to just kind of manipulating doing add many things stopping and starting tasks you can start to do some developer e stuff you can create a list with PowerShell you can edit the items in a list in PowerShell you can you know create VMs lots of lots of cool stuff so it's all we're kind of learning and putting all these little pieces in place so the next concept I want to talk about here is variables and so with variables with PowerShell they're always prefaced with a dollar sign and the nice thing about PowerShell variables is it to create one you literally just type it so dollar sign zebra for our friends bold zebras yeah and we just say equals and then we could do get process Microsoft edge again so just like that what happens is PowerShell is pretty smart it says all you pass me this type of object into the variable so assign the value of the variable to correspond with that and one of the things you always want to do after you set a variable you just want to do it you can tab completed as well there's my tab key and that just confirms for me that something did get set the variable it's always a good idea after you set a variable to just type that single hand to troubleshoot you know you hate to set a blank variable because you've had a typo and if they fight with why can't manipulate that variable so now the dollar sign zebra is in there I have that object right it's not just these words on the screen it's the actual whole object I could do dollar sign zebra and then dot and then if I start tabbing right dollar sign there's name so make sure save Microsoft edge so I'm tabbing through you tab through the properties and the methods so this is how you can really drill in and start to do a lot more with it so for example earlier we saw there was a method called kill all right and so dollar sign zero kill and then open and close parentheses look down here at the bottom we got get service the edge window boom no more Microsoft edge because we were able to use the method of kill the kill that process so a lot of fun to be had you know this is the type of stuff we're going to kind of continue to get in through the series but it's starting to help you hopefully see that there good value in understanding more about PowerShell as well thanks to the variables so a couple more things here and we'll finish up almost done so great things here for you to Nova is get - history and so what get does history is you can probably guess now it's just a list of all the powershell commandlets i've ran in this session it's not saved anywhere it's just available here but right if I start pressing my up key I can put my way through those I can't manipulate it - I can go half way up there and do it so it's important to know you go up and down and you know you use git history to kind of rattle your brain what were you playing with there the last thing I want to show you here was we did the start transcript earlier and so what I'm going to do is I'm gonna go here my PC and okay so here is the transcript for this particular session so you can see I had to open it from my PC location and when we did the start transcript it told us where it put it but so then this is everything that we did the entire session clearly we don't want to rehash all that but there's a lot of stuff but start - transcript was what gave us all of that Thanks and by default or you can when you do start - transcript it puts it in your Documents folder for you you can manipulate that right it's so if I want to figure out I manipulate does it say start out saying get - help start - trance script and you can see that you know you can set a path here you can do a pin you can force it all types of fun things so it gives you options for controlling where those go and I bet if we do I didn't check this earlier hope I'm not wrong I bet if we do examples there you go so start training script path this location no clobber and it would stop anything else from your overwritten so pretty cool stuff all right so I think that will get us through the core basics we want to run so in the next session what we're going to do when we slide this over so you can see it is we're actually going to talk about this script so we're going to take everything we just did here and go really fast and alright so you can see we're getting into or we're gonna run a command led we're going to pipe it over to a wear object so we're going to do some kind of filtering there and then we're going to talk about this you know these things like - GT for greater than and then we're going to learn about some looping right so for each object we're going to write out we're going to do some math it will be a good time so and don't judge my script my script is terrible if better ways to do it but it's a great script to actually teach you guys how to do things so that'll be next time okay so that finishes it up for today hopefully you enjoyed it remember this is part one of mini so definitely check out the rest of the series as you go along and leave me comments on things you'd like to see more of less of things I did that we're confusing always happy to the subsequent videos kind of come back and revisit some of those different topics as well and also you can subscribe to the channel if that is the type of stuff you enjoy seeing and then you can hit me up on Twitter at Shane's cows or if you want to work together on a project good old bold zebras calm Thanks have a great day
Info
Channel: Shane Young
Views: 1,102,784
Rating: 4.9203639 out of 5
Keywords: PowerShell, Microsoft, Windows, Windows PowerShell, PowerShell intro, get-command, start-transcript, get-alias, PowerShell 4.0, getting started with powershell, powershell scripting for beginners, powershell basics, powershell tutorials, powershell scripting, powershell, powershell intro, powershell tutorial, powershell for beginners, windows powershell for beginners, powershell training for beginners, powershell 4.0 for beginners, learn powershell, PowerShell basics, Shane Young
Id: IHrGresKu2w
Channel Id: undefined
Length: 27min 56sec (1676 seconds)
Published: Mon Sep 12 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.