PowerShell Cmdlet Deep Dive: Get-Verb
Welcome back to Wahmans PowerShell Blog! In today’s post, we’re diving into a lesser-known but incredibly useful cmdlet: Get-Verb
.
The Get-Verb
cmdlet retrieves all the approved PowerShell verbs that are recommended for writing advanced functions and cmdlets. Using standardized verbs helps you write consistent, user-friendly PowerShell code that’s easy to understand and share with others.
Why Use Get-Verb?
When writing functions or publishing your own modules, you should use approved verbs to maintain consistency across the PowerShell community. Not only does it improve readability, but it also aids in discoverability when users try to find cmdlets with standardized naming.
Let’s Get Started With Some Examples
Example 1: List All Approved Verbs (Beginner)
If you simply want to see all the approved verbs in your current version of PowerShell:
Get-Verb
This will return a list of objects that includes each verb, its group (such as Common or Security), and its synonym if any.
Example 2: Filter Verbs by Group (Intermediate)
Say you’re interested only in verbs related to communications:
Get-Verb | Where-Object { $_.Group -eq 'Communications' }
This filters the list to show only verbs that are categorized under the Communications
group.
Example 3: Validate a Custom Verb (Intermediate)
If you’re creating a new function and want to ensure your custom verb follows PowerShell standards:
$myVerb = 'Compile'
if (Get-Verb | Where-Object { $_.Verb -eq $myVerb }) {
"'$myVerb' is an approved PowerShell verb."
} else {
"Warning: '$myVerb' is not an approved PowerShell verb."
}
This helps maintain consistency when you’re writing your own toolset or module.
Example 4: Generate a Report of All Verbs and Their Groups (Advanced)
Let’s say you want to generate a quick summary for documentation purposes:
Get-Verb |
Sort-Object Group, Verb |
Select-Object Verb, Group |
Export-Csv -Path "ApprovedVerbsReport.csv" -NoTypeInformation
This script sorts the verbs by group and name, selects only the important properties, and exports them to a CSV file so you can integrate them into documentation or share with your team.
Conclusion
Get-Verb
may seem simple on the surface, but it plays an important role in writing professional PowerShell. By using approved verbs, you’re helping to keep scripts readable, maintainable, and consistent with PowerShell best practices.
Happy scripting, and I will see you in the next post!
Leave a Reply