Powershell-Major Features

Major Features:

  • Cmdlets
  • Pipeline
  • Providers
  • Help System

 


Cmdlets (also pronounced it “command-let”)
 are probably the most obvious feature when comparing Powershell to other scripting language. A cmdlet is a small, self contained piece of functionality that does one specific job.

For example: Get-command | Where {$_.pssnapin -like “Microsoft.p*.”}). count

 

The Get-Command generates a list Powershell commands and list is piped in a filter 

..(Where is the an alias or shorthand for where-object) that accepts those commands installed by a Powershell snapin. The method of extending powershell whose names start Microsoft P. Then count the number of commands in the filerterd list. As illustrated in Figure #1.

Figure#1.
PS C:\Users\ (Get-Command |where {$_.pssnapin -like “Microsoft.p*” } ).count
60

powershellgetcommand

Cases and Operators:
The operator -like is used to perform the comparison in the Figure#1- For example,  

All cmd-lets has a verb-noun syntax. It starts with verb. The second part is a nount that describes what the verb is actingin on – in this case.

Get-Command with -Noun and -Verb

As you get to know PowerShell better so you become familiar with verbs such as ‘Set’ or ‘Get’ and nouns such as ‘Process’ or ‘Computer’.  This is why I now prefer to filter Get-Command with -Noun or -Verb.  One of my greatest successes was finding ‘Restart-Service’.  I had used start and stop-service, but when I tried this filter I unearthed the useful Restart-Service.

# PowerShell Get-Command Nouns
Clear-Host
Get-Command -Noun Service

Also Verbs

# PowerShell Get-Command Nouns
Clear-Host
Get-Command -Verb S*

Note 2: I could have chosen -Verb Set, but I wanted to show you that -Verb also take wildcards*.

Get-Command -Module

Firstly list your modules with Get-Module.  Make your selection, for example, ISE.

# PowerShell Get-Command Module info
Clear-Host
Get-Module ISE

Here is another example which imports a modules then checks the cmdlets.

$Baskets = “PSDiagnostics”
Import-Module $Baskets
Get-Command -Module $Baskets

Tab Completion:
Powershell demonstrators another feature that aids productivity: Tab completion. If you type Get- and press tab key, the PowerShell engine will complete the command with the first cmdlets that matches what been typed.

As with the cmdlets names, the more of the paramters name you give, the sooner the process brings.

Aliases
As an alternative to typing the full name of a cmdlet or parameters, it’s possible to use an alias.

alaispowershell

Creating a New Windows PowerShell Alias

So you say that you like Windows PowerShell, but you have problems remembering some of the cmdlet names? Well, then why not create an alias for those cmdlets, an alias that you can remember? For example, maybe you’d prefer to type show instead of Get-ChildItem. If that’s the case, then you can use the New-Alias cmdlet to map the term show to Get-ChildItem. All you have to do is call New-Alias followed by the alias name (show) and the cmdlet the alias is being mapped to (Get-ChildItem). You know, something like this:

New-Alias show Get-ChildItem

Now, what do you suppose will happen the next time you type show in the Windows PowerShell console? You got it:

Windows PowerShell
By default, aliases are not saved between Windows PowerShell sessions: each time you restart Windows PowerShell you’ll need to recreate the alias. To ensure that your new aliases survive between Windows PowerShell sessions, create a PSConfiguration folder in your Windows PowerShell profile folder. For example:

C:\Documents and Settings\gstemp\My Documents\PSConfiguration

Note. How are you supposed to know your Windows PowerShell profile folder? Just type this command:

Get-Variable profile | Format-List

In the PSConfiguration folder, create a file named Microsoft.PowerShell_profile.ps1 and add the following command to the file:

Set-Alias show Get-ChildItem

 

 

 

 

Reference:
Powershell cmdlet Verb-Noun 
https://technet.microsoft.com/en-us/library/dd315315.aspx


Leave a Reply

Your email address will not be published. Required fields are marked *