PowerShell uses its own scripting language, commonly called the PowerShell language. It is built on top of the .NET Framework (or .NET) and works with .NET objects rather than plain text.
The PowerShell language includes:
- Shell language keywords such as
for,foreach,try,catch, andtrap. - A rich scripting syntax with looping, conditions, flow control, and variable assignment, similar in style to C#.
Commands used in PowerShell fall into several categories:
- Cmdlets
- Native PowerShell commands, not stand-alone executables.
- Named using a Verb-Noun pattern, for example:
-
Get-Command– lists commands available in the shell -
Set-Location– changes the current directory -
Get-ChildItem– lists items in a directory
-
- Cmdlets are grouped into modules and can be written in any compiled .NET language or in PowerShell itself.
- Shell language keywords
- Built into the language and used for control flow and script structure, for example:
-
if,else,for,foreach,try,catch,trap
-
- OS-native commands
- Executable files and scripts provided by the operating system, such as
sort.exeor.cmdbatch files. - PowerShell can run these just like other shells.
- PowerShell-specific commands in scripts, functions, and modules
- Scripts (
.ps1files) - Functions defined in PowerShell
- Methods exposed by .NET objects
PowerShell also provides operators and helper commands to run other commands, for example:
- Call operator
&to execute a command stored in a variable or string. -
Start-Processto start native processes with options like different credentials or redirected input/output. -
Invoke-Itemto perform the default action for a file or URL (for example, open a URL in the default browser).
References: