• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Stephanos Constantinou Blog

PowerShell Scripting

  • Home
  • Blogs
    • PowerShell Tutorials
    • PowerShell Scripts
    • PowerShell Modules
      • Modules Cmdlets
    • Software Reviews
  • About
  • Contact
You are here: Home / PowerShell Tutorials / PowerShell Language Keywords

PowerShell Language Keywords

27/09/2018 by Stephanos Leave a Comment

PowerShell Language Keywords

In this tutorial we will see about PowerShell Language Keywords. PowerShell Keywords are used in order to perform a specific action. For this tutorial we will see the list of keywords and the syntax of each one. In related links section you will be able to find a link for each of the keywords in order to check more information about them. I will write a different post for each one of them, in order to see in detail the use of them. Consider this as an introduction to PoowerShell Keywords.

[adinserter name=”In Article”]

Keyword List

  • Begin – It specifies one part of the body of a function and runs one time before any objects are received from the pipeline.
  • Break – It causes a script to exit a loop.
  • Catch – It specifies a statement list to run if an error occurs in the accompanying Try statement list.
  • Class – It specifies a new class in PowerShell.
  • Continue – It causes a script to stop running a loop and to go back to the condition. If the condition is met, the script begins the loop again.
  • Data – It defines a section that isolates data from the script logic.
  • Define – Reserved for future use
  • Do – It is used with the While or Until keyword as a looping construct.
  • DynamicParam – It specifies one part of the body of a function. Dynamic parameters are added at run time.
  • Else – It is used with the If keyword to specify the default statement list.
  • Elseif – It is used with the If and Else keywords to specify additional conditionals. The Else keyword is optional.
  • End – It specifies one part of the body of a function and runs one time after all the objects have been received from the pipeline.
  • Enum – It is used to declare an enumeration, a distinct type that consists of a set of named labels called the enumerator list.
  • Exit – It causes PowerShell to exit a script or a PowerShell instance.
  • Filter – It specifies a function in which the statement list runs one time for each input object. It has the same effect as a function that contains only a Process block.
  • Finally – It defines a statement list that runs after statements that are associated with Try and Catch.
  • For – It defines a loop by using a condition.
  • ForEach – It defines a loop by using each member of a collection.
  • From – Reserved for future use.
  • Function – It creates a named statement list of reusable code.
  • Hidden – It hides class members from the default results of the Get-Member cmdlet, and from IntelliSense and tab completion results.
  • If – It defines a conditional.
  • In – It is used in a ForEach statement to create a loop that uses each member of a collection.
  • InlineScript – It runs workflow commands in a shared PowerShell session. InlineScript is valid only in a PowerShell Workflow.
  • Param – It defines the parameters in a function.
  • Process – It specifies a part of the body of a function.
  • Return – It causes PowerShell to leave the current scope and writes the optional expression to the output.
  • Static – It specifies the property or method defined is common to all instances of the class in which is defined.
  • Switch – The Switch statement is equivalent to a series of If statements, but it is simpler.
  • Throw – It throws an object as an error.
  • Trap – It defines a statement list to be run if an error is encountered.
  • Try – It defines a statement list to be checked for errors while the statements run.
  • Until – It is used in a Do statement as a looping construct where the statement list is executed at least one time.
  • Using – It allows to indicate which namespaces are used in the session.
  • Var – Reserved for future use.
  • While  – It is used in a Do statement as a looping construct where the statement list is executed at least one time.

[adinserter name=”In Article”]

Function – Param – DynamicParam – Begin – Process – End

Syntax:

function [<scope:>]<name> [([type]$parameter1[,[type]$parameter2])]
{
  param([type]$parameter1 [,[type]$parameter2])
  dynamicparam {<statement list>}
  begin {<statement list>}
  process {<statement list>}
  end {<statement list>}
}

Try – Catch – Finally

Syntax:

try {<statement list>}
catch [[<error type>][',' <error type>]*] {<statement list>}
finally {<statement list>}

Classes – Static

Classes are declared using the following syntax:

class <class-name> [: [<base-class>][,<interface-list]] {
    [[<attribute>] [hidden] [static] <property-definition> ...]
    [<class-name>([<constructor-argument-list>])
      {<constructor-statement-list>} ...]
    [[<attribute>] [hidden] [static] <method-definition> ...]
}

Classes are instantiated using either of the following syntaxes:

[$<variable-name> =] New-Object -TypeName <class-name> [
  [-ArgumentList] <constructor-argument-list>]
[$<variable-name> =] [<class-name>]::new([<constructor-argument-list>])

[adinserter name=”In Article”]

Data

Syntax:

DATA [-supportedCommand <cmdlet-name>] {
    <Permitted content>
}

Do-While – Do-Until

Do-While Syntax:

do {<statement list>} while (<condition>)

Do-Until Syntax:

do {<statement list>} until (<condition>)

If – Elseif – Else

Syntax:

if (<test1>)
    {<statement list 1>}
[elseif (<test2>)
    {<statement list 2>}]
[else
    {<statement list 3>}]

Enum

Basic Syntax:

enum <enum-name> {
    <label> [= <int-value>]
    ...
}

Flags Syntax:

[Flags()] enum <enum-name> {
    <label 0> [= 1]
    <label 1> [= 2]
    <label 2> [= 4]
    <label 3> [= 8]
    ...
}

[adinserter name=”In Article”]

Filter

Syntax:

filter [<scope:>]<name> {<statement list>}

For

Syntax:

for (<init>; <condition>; <repeat>)
{<statement list>}

ForEach – In

Syntax:

foreach ($<item> in $<collection>){<statement list>}

Return

Syntax:

return [<expression>]

Switch

Syntax:

Switch (<test-value>)
{
    <condition> {<action>}
    <condition> {<action>}
}

[adinserter name=”In Article”]

Throw

Syntax:

throw [<expression>]

Trap

Syntax:

trap [[<error type>]] {<statement list>}

Using

Syntax to reference .Net Framework namespaces:

using namespace <.Net-framework-namespace>

Syntax to reference PowerShell modules:

using module <module-name>

I hope the tutorial about PowerShell Language Keywords is helpful.

Please let me know your comments and thoughts.

You feedback is appreciated.

[adinserter name=”In Article”]

Related Links

  • PowerShell Tutorials
  • PowerShell Scripts
  • About Language Keywords | Microsoft Docs
  • about_Functions | Microsoft Docs
  • about_Functions_Advanced | Microsoft Docs
  • about_Break | Microsoft Docs
  • about_Trap | Microsoft Docs
  • about_Try_Catch_Finally | Microsoft Docs
  • PowerShell Try Catch Finally – Stephanos Constantinou Blog
  • about_Classes | Microsoft Docs
  • about_Continue | Microsoft Docs
  • about_Trap | Microsoft Docs
  • about_Data_Sections | Microsoft Docs
  • about_Do | Microsoft Docs
  • about_While | Microsoft Docs
  • about_Functions_Advanced_Parameters | Microsoft Docs
  • about_If | Microsoft Docs
  • about_Functions_Advanced_Methods | Microsoft Docs
  • about_Enum | Microsoft Docs
  • about_For | Microsoft Docs
  • about_Foreach | Microsoft Docs
  • about_Hidden | Microsoft Docs
  • about_Return | Microsoft Docs
  • about_Switch | Microsoft Docs
  • about_Throw | Microsoft Docs
  • about_Using | Microsoft Docs

[adinserter name=”Matched-Content”]

Summary
PowerShell Language Keywords
Article Name
PowerShell Language Keywords
Description
PowerShell Language Keywords. In this tutorial you will find information about PowerShell Language Keywords and their use. Stephanos Constantinou Blog
Author
Stephanos
Publisher Name
Stephanos Constantinou Blog
Publisher Logo
Stephanos Constantinou Blog

Filed Under: PowerShell Tutorials Tagged With: PowerShell Keywords

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Footer

Recent Posts

  • ICS Cube Product Review 26/04/2019
  • PowerShell Module SysInfo v1.2.0 15/03/2019
  • PowerShell Module SysInfo v1.1.2 13/11/2018
  • PowerShell Module SysInfo 24/10/2018
  • Get-VoltageProbe 24/10/2018
  • Get-VideoController 24/10/2018
  • Get-USBController 24/10/2018
  • Get-TrackPoint 24/10/2018
  • Get-TrackBall 24/10/2018
  • Get-TouchScreen 24/10/2018
Planet PowerShell

Categories

  • Modules Cmdlets (57)
  • PowerShell Modules (5)
  • PowerShell Scripts (38)
  • PowerShell Tutorials (35)
  • Software Reviews (2)

Archives

  • April 2019 (1)
  • March 2019 (1)
  • November 2018 (1)
  • October 2018 (56)
  • September 2018 (13)
  • August 2018 (9)
  • July 2018 (6)
  • June 2018 (8)
  • May 2018 (7)
  • April 2018 (9)
  • March 2018 (4)
  • February 2018 (6)
  • January 2018 (12)
  • December 2017 (4)
Top 10 PowerShell 2018

Blogroll

  • Planet PowerShell
  • Reddit – PowerShell
  • PowerShell Magazine
  • PowerShell.org
  • PowerShell Team Blog
  • Hey, Scripting Guy! Blog
  • Mike F Robbins
  • PowerShell Explained with Kevin Marquette
  • Mike Kanakos – Network Admin
  • The Lonely Administrator
  • AskME4Tech
PowerShell Blogs Sysadmin Blogs Banners for Top 20 Programming Blogs

© 2023 · Stephanos Constantinou Blog

  • Home
  • Blogs
  • About
  • Contact
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok