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 useDo
– 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”]


Leave a Reply