Demonstration of using Parameters

Kevin Brown
A free video tutorial from Kevin Brown
Windows, Azure, AWS, Cisco, Security Instructor & Author
4.5 instructor rating • 12 courses • 48,715 students

Lecture description

Powershell parameter demonstration

Learn more from the full course

PowerShell version 5.1 and 6: Step-by-Step

Exactly what you need to know to use PowerShell effectively

06:03:53 of on-demand video • Updated August 2020

  • Understand PowerShell principles and tools
  • Manage processes and services using PowerShell
  • Manage scripts using PowerShell ISE
  • Using different versions of PowerShell
  • How to use PowerShell Help
  • Automate tasks
  • Use of the Pipeline
  • How to create transcripts
  • Work with Object Members
  • Create hash tables
  • create arrays
  • Use operators and parameters
  • Use WMI and CIM commands
  • Proper use of variables
  • Understand execution policy levels
  • Create scripts based on ForEach and ElseIf constructs
  • Use PowerShell remoting
  • How to use Aliases
English [Auto] One of the most common things you'll use in power Shell will be parameters to look at a parameter. I'm going to run this command and power shell get dash service if I run that command by itself it executes I'm to scroll back to the top and we can see that running that command by itself generates a status for the service generates the name of the service and a user friendly display may so no parameters just the command itself. That's what it actually returns. I'm going to scroll up a bit here to bring this to the top if we run get bash service Dash. Name. I can specify the name of any service I'm going to choose this w search so when I run get that service dash name w search it just returns the status of that w search. So I see it as running name and I see the user friendly display name show up dash. Name is a parameter. Now I did not have to type it in before because it is invisibly attached. That is the actual term in power show. Invisible an invisible parameter means you do not have to type it. It's gonna just execute if you run the command let itself in power shell. This is a required parameter. Now it is invisible so you do not have to type it but it's also a required parameter. Meaning if you run the command by itself it automatically applies this parameter some commands will prompt you for required parameters. Others will just execute with a default configuration. For example if I run the command get dash event log and just hit enter. It says oh you have to specify a log name that's required. Can't run this command without a low name log name as a required parameter. I did not specify the parameter so for this it just says you got to type one in because it's overall hundreds of logs. But that parameter is still invisibly attached. It just forces me to type a value where they get service did not force me to type of value. If you ran that it just generated a list of all the services. So some will execute some will prompt but both are required parameters. I'm on it control see here because I don't actual the type the name of a log to view the parameters to know which ones are required and which ones are not required. I'm going to run this command get dash help get dash service one of our upcoming lessons actually covers get bash help in great detail but in short get dash help gives us syntax examples a description of whatever command you type behind it. So if you just want additional info about the get dire service just put the get that help in front of it then run get that service and it gives you some information. Someone hit enter the run that now if we do scroll up a bit gives me some syntax here so the syntax for this I can see that I have these brackets. So this is one entire parameter where it's double bracket then it's dash name. No one in bracket string then it's these brackets here and in bracket here. What we care about. Notice Dash. Name that parameter is wrapped in its own bracket. That means it's a required parameter compare that to this one dash computer name string is wrapped in a single set of brackets not double brackets like the dash main. That means it's an optional parameter you do not have to include it. If it were a required parameter there would be another bracket here in the front. So this would be double brackets. And right behind computer name here there would be a close bracket or in brackets some people call it with those with those brackets. You can look at the syntax and determine if a parameter is required or optional if we run get dash service. Again I'm triple type dash and hit tab. Name is the first on the list that's our required parameter. If I hit tab again it goes up to computer name. We know that's optional. So these other parameters here are all optional parameters. Only the name parameter is required. And again if we scroll back up we know that's true because no other parameter no other parameter is wrapped in double brackets like this note. If you go through the list this is the only one all the others are just single brackets if we run that get help. With kit dash event log we'll scroll up a little bit to the syntax you can see here. Now it's not in double brackets for this one. It looks a little different but I can see log name is wrapped in brackets and string is behind it not wrapped in brackets for some syntax you'll see it that way. So either double brackets or a parameter wrapped in brackets with a string behind it would be required. So you would know that's a required parameter and since Idi is a required parameter so some of these are required some are not. For example if I look at the dash before the dash before date time is wrapped. The entire thing is wrapped in brackets meaning it's not required either the parameter itself is going to be wrapped in brackets with a string behind it or it's gonna be in double brackets if it has no string and it's just the parameter itself. So those are the only two times you'll ever see required parameters every other parameter you see would just be like this just looking at that we know it is not a required parameter. If it were required again it would either be double brackets in the front or computer name would have been in its own bracket. So that would have been a close bracket here. That would have denoted that it's a required parameter an easier place to actually look at this is in the integrated scripting engine. So in power shell I'm trying to type ISC and it opens the power cell integrator scripting engine. This is one of the most useful tools if not the most useful tool that we actually have. If I run get dash service and type dash it gives you a list of all the parameters that you can actually use. This is called intelligence meaning it is aware of the command I typed in the front so it knows I type. Get that service so it generates this list based directly on that extremely useful. So I could run get that service dash name or just click that then through this intelligence it says oh here is a list of all the services on your machine. Which service do you actually want while I'm still type W and it automatically filters down the WD. The more you type the more it searches. So I'm type W S E W search as the only service with W S E so I could just hit enter or click that and it generates that at the top I can click this little play button to run the script or if you have multiple lines here and you only want to run one. You can either hit F eight on the keyboard or run selection. I only have one line so it does not matter which one i click here. But you'll see when I click the play button to run that it just executes the same as if we're in the partial prompt. Now I'm gonna switch back to the power shall console itself. So back to the prompt here. If we were to run the get dash service here dash name it does not display a list of names but if I hit tab and keep tab and it actually does tab through all the possible names. Now it's a lot of services so I could type dash name W and then hit tab and it only searches two services to start with. W if we decide W S W S C service w search so only those two and I can hit enter and that would execute the site that is called Power shall in telesales extremely useful.