Updated March 8, 2023
Introduction to PowerShell Verbs
The following article provides an outline for PowerShell Verbs. All the PowerShell cmdlets are designed in a verb-noun pattern which is separated by a hyphen. The noun denotes the entity on which the action is taken, and the verb part signifies the action the cmdlet will perform. All the cmdlets also include an approved verb alias prefix. This is used as an alias for that cmdlet. PowerShell verb definition differs from the actual meaning of the English language. New is considered as an action in the PowerShell context, whereas it is not a verb in English language definition.
Syntax of PowerShell Verbs
The Get-Verb cmdlet retrieves the list of approved verbs in PowerShell.
Get-Verb [[-Verb] <String>] [[-Group] <String>] [<CommonParameters>]
There are cmdlets with unapproved verbs and can be run. A warning will be displayed when the unapproved cmdlet is imported using Import-Module.
- -Group: This parameter denotes the name of the groups to be retrieved. Its data type is String. It was introduced only from PowerShell version 6.0. Its default value is All verbs. It accepts pipeline input, but wildcard characters are not allowed.
- -Verb: This specifies the verbs that need to be fetched. Its data type is String. Its default value is all groups. It accepts pipeline input; also, wildcard characters are allowed. Some of its accepted values are common, communications, security, other, lifecycle, data and diagnostic.
PowerShell verbs are grouped together based on their use. It makes them easy to find.
The below are the groups:
- Common: Defines common actions that be assigned to any cmdlet like add.
- Communications: Defines actions such as connect.
- Data: This is related to data handline like a backup.
- Diagnostic: Define actions such as debug.
- Lifecycle: Define actions associated with a lifecycle, such as complete.
- Security: Security related actions such as revoke.
- Other: Related to all the other actions.
The below recommendations must be kept in mind when naming a verb for the cmdlet to maintain consistency between cmdlets that are created new, cmdlets supported by PowerShell and cmdlets created by others.
- It is advisable to use one of the predefined verbs.
- The verb should describe the action’s scope.
- Never use alternatives of an approved verb.
- The form of the verb should be the same as listed already.
- The reserved verbs such as foreach, sort, where, tee, ping, group and format shouldn’t be used.
Differences Between Similar Verbs but Different Actions
Given below are the differences between similar verbs but different actions:
- New & Set: The new keyword is used to create a new verb; the set is used to set a value.
- Find & Search: Find verb is used for looking up to an object. Search basically creates a reference to a source.
- Get & Read: Get is used to fetch access to a resource, whereas read is used to extract information from a resource.
- Invoke & Start: Invoke is used to trigger synchronous operations, whereas start is used in the case of asynchronous operations.
Verbs and their Action
Given below are the verbs and their action:
1. Common Verbs
- Add: This adds a new resource to a container or attaches a new item to an existing item. Its alias is a. This verb is paired with Remove. The following words, such as append, attach, insert and concatenate, should be avoided while creating as they are synonyms. E.g. Add-Content.
- Clear: This is used to remove items from a resource container but doesn’t delete them. Its alias is cl. The following words, such as nullify, unset, erase, and release, should be avoided while creating synonyms. E.g. Clear-Content.
- Close: This is used to make a resource unavailable. Its alias is cs. This is paired with open.
- Find(fd): This is used for finding a resource inside a container. Its alias is fd. The synonym that should be avoided is Search.
- Move: This is used to move items from a resource container to another but doesn’t delete them. Its alias is m. The following words, such as transfer and migrate, should be avoided while creating as they are synonyms. E.g. move-Item.
- Pop: Removes the topmost item from the stack. E.g. Pop-Location.
- Push: This is used to add an item to the topmost location in a stack. E.g. Push-Location.
2. Communication Verbs
- Connect: This is used to connect a source and destination. It is paired with Disconnect. Join, and Telnet are the synonyms to be avoided. Its alias is cc.
- Disconnect: This is used to break a source and destination. It is paired with Connect. Break and logoff are the synonyms to be avoided. Its alias is dc.
- Receive: This is used to accept information from a source. It is paired with send. Read, accept and peek are the synonyms to be avoided. Its alias is rd.
- Send: This is used to deliver information to a destination. It is paired with receive. Broadcast and put are the synonyms to be avoided. Its alias is sd.
3. Data Verbs
- Checkpoint: It creates a snapshot of the current state. Diff is the synonym to be avoided. Its alias is ch.
- Compare: This compares data from two resources. Diff is the synonym to be avoided. Its alias is cr.
- ConvertFrom: This is used to convert primary input to other supported types. Its alias is cf. Export and output are the synonyms to be avoided.
- ConvertTo: This is used to convert other input to the primary type. Its alias is ct. Import and input are the synonyms to be avoided.
4. Diagnostic Verbs
- Debug: This is used to trouble shoot and debug issues. Its alias is db. Diagnose is the synonym to be avoided.
- Trace: This is used to trace the resource activities. Its alias is tr. Follow, track and inspect are some of the synonyms to be avoided.
5. Lifecycle Verbs
- Register: This creates an entry for resource in the repository. Its alias is rg and is paired with unregister.
- Restart: This is used to restart an operation after stopping it. Its alias is rt. Recycle is the synonym to be avoided.
6. Security Verbs
- Block: This blocks access to a resource. It is paired with unblock. Its alias is bl. Prevent and deny are the synonyms to be avoided.
- Protect: This shields a resource from any attack. It is paired with unprotect. Its alias is pt. Encrypt and safeguard are the synonyms to be avoided.
Example of PowerShell Verbs
Given below is the example of PowerShell Verbs:
Write-Host "Example of verbs in PowerShell" -ForegroundColor Green
Write-Host "Fetching top 10 verbs" -ForegroundColor Green
Get-Verb | Select-Object -first 10
Write-Host "get list of approved verbs begins with a" -ForegroundColor Green
Write-Host "get list of approved verbs that begin with c" -ForegroundColor Green
Thus, the article explained in detail about verbs in PowerShell, their naming convention, different types of verbs and their aliases.
This is a guide to PowerShell Verbs. Here we discuss naming recommendation, differences between similar verbs but different actions, verbs & their action, example. You may also have a look at the following articles to learn more –