Using PowerShell cmdlets.md - Juan-bit94/Ops401D10 GitHub Wiki

Using PowerShell cmdlets

  • In PowerShell, we have things called cmdlets and they're basically the commands that you use. So just think of the shortened version cmd as being command, and command-lets is how it's pronounced.
  • Now cmdlets have a very strict syntax of verb singular noun followed by parameters. And there are about 100 verbs approved by the PowerShell team, although there's no way to really enforce that.
  • I mean if you created your own cmdlet, you could choose any verb you want, but there is a specified set of best practices. A list of approved verbs because standardization is important.
  • Now, we will just going to look at a couple of the basic commands in PowerShell, probably the most common one is the get command. And it looks like this:
    • get-command and then I put a space, and another dash and in this case, what I want to do is I want to get information on a module, and notice how the color coding is happening there, and that's because the PowerShell interface is recognizing the various elements here and doing the code highlighting or code coloring for us.
    • Now in this case, what I want to do is get information on a module in Windows Server called servermanager and just press enter. And there you can see the various items that comes back with the PowerShell information on Server Manager. And as you can see, there are different types of commands, we have Aliases, we have Functions and we have the Cmdlets themselves. So let's take a look at something else.
      • Example:
        • get-command -module servermanager
    • Now this time, what I'm going to do is use a shortened version of this, gcm, which is short for the get command. You will find that in PowerShell there's a lot of different ways of shortening information that just makes typing that much easier.
      • Example:
        • gmc -module servermanager
      • You will get the same results. So as you can see, gcm is just a shortened version of the get command. Let's clear that with cls. Now let's try something else. gcm for the get command and in this case, I'm going to search on a name, so I'll use a -name, and then I'm going to use asterisks, and this is going to allow me to do this.
      • I'm going to encase the word get in asterisks. And when I press enter, it's going to show me all the various PowerShell commands, functions, aliases, or cmdlets, functions, and aliases that are available for the get command. And that just means that they contain the word get.
      • Example:
        • gcm -name "get"
  • Let's take a look at something else here. I'll scroll down, gcm -name let's try IP and press enter - Example: - gcm -name "IP"
    • You will see all the various aliases, functions, cmdlets, and even applications that encompass the term or the word IP. So the basic command structure of PowerShell is fairly straightforward.
  • Remember, that we do have this strict syntax of verb and then singular noun and then the parameters. There's going to be a lot of memorization and a lot of using the help system, especially in the PowerShell ISE in order to use PowerShell effectively.