Structure and Naming


Module

Modules can be used to package and distribute cohesive libraries of functions that perform common tasks. Typically, the names of these functions share one or more nouns that reflect the common task that they are used for. These functions can also be similar to .NET Framework classes in that they can have public and private members. For example, a library can contain a set of functions for file transfers. In this case, the noun reflecting the common task might be “file.”

  • Modules can be used to customize your environment by adding specific cmdlets, providers, functions, and variables.

Cmdlet

A cmdlet is a lightweight command that is used in the Windows PowerShell environment. Cmdlets perform an action and typically return a Microsoft .NET Framework object to the next command in the pipeline.

Cmdlets differ from commands in other command-shell environments in the following ways:

  • Cmdlets are instances of .NET Framework classes; they are not stand-alone executables.
  • Cmdlets can be created from as few as a dozen lines of code.

  • Cmdlets do not generally do their own parsing, error presentation, or output formatting. Parsing, error presentation, and output formatting are handled by the Windows PowerShell runtime.

  • Cmdlets process input objects from the pipeline rather than from streams of text, and cmdlets typically deliver objects as output to the pipeline.

  • Cmdlets are record-oriented because they process a single object at a time.

A cmdlet, which is expressed as a verb-noun pair, has a .ps1 extension. Each cmdlet has a help file that can be accessed by typing Get-Help <cmdlet-Name> -Detailed. The detailed view of the cmdlet help file includes a description of the cmdlet, the command syntax, descriptions of the parameters and an example that demonstrate the use of the cmdlet.


Command structure

Every command in PowerShell is composed of 2 parts:

  • Do something-To something
Verb-Noun   # Get-Help, Get-Command, Get-Service, Set-Service, etc.
Verb        # Add,Clear,Copy,Enter,Exit,Get,Join,Move,Push,Remove,Set etc.
-Noun       # Service,Command,Content,Date,Event,Process etc.

You can see a list of all available verbs online or with bellow cmdlet:

  • Shows only verbs that starts with s
get-verb -verb s*
Verb    Group
----    -----
Search  Common
Select  Common
Set     Common
Show    Common
Skip    Common
Split   Common
Step    Common
Switch  Common
Save    Data
Sync    Data
Start   Lifecycle
Stop    Lifecycle
Submit  Lifecycle
Suspend Lifecycle
Send    Communications

Aliases

Some cmdlets have also aliases that are similar to unix-like commands.

  • Show all aliases that starts with c
get-alias -name c*
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           cat -> Get-Content
Alias           cd -> Set-Location
Alias           CFS -> ConvertFrom-String                          3.1.0.0    Microsoft.PowerShell.Utility
Alias           clc -> Clear-Content
Alias           clear -> Clear-Host
Alias           clhy -> Clear-History
Alias           cli -> Clear-Item
Alias           clp -> Clear-ItemProperty
Alias           cls -> Clear-Host
Alias           clv -> Clear-Variable
Alias           cnsn -> Connect-PSSession
Alias           compare -> Compare-Object
Alias           copy -> Copy-Item
Alias           cp -> Copy-Item
Alias           cpi -> Copy-Item
Alias           cpp -> Copy-ItemProperty
Alias           curl -> Invoke-WebRequest
Alias           cvpa -> Convert-Path
Alias           chdir -> Set-Location

results matching ""

    No results matching ""