.cmdletname { font-size:large } .cmdletsynopsis { font-size:medium } .cmdletdescription { font-size:medium } .cmdletparameters { font-size:medium } th { font-size: medium; font-style: italic } table { border: 1 }
When I write a PowerShell function, I try to ensure that it follows the PowerShell standard verbs. These verbs actually exist as static properties in a few different types in PowerShell, so I thought I’d make a quick advanced function so I can get all of the Verbs. Check it out:
Get-Verb
Synopsis:
Gets the standard PowerShell verbs
Syntax:
Get-Verb [[-verb] [<String[]>]] [-Verbose] [-Debug] [-ErrorAction [<ActionPreference>]] [-WarningAction [<ActionPreference>]] [-ErrorVariable [<String>]] [-WarningVariable [<String>]] [-OutVariable [<String>]] [-OutBuffer [<Int32>]] [<CommonParameters>]
Detailed Description:
Uses reflection to get the standard PowerShell verbs and return them as a property bag
Examples:
-------------------------- EXAMPLE 1 -------------------------- # Gets all verbs Get-Verb
-------------------------- EXAMPLE 2 -------------------------- # Gets a random verb and searches for commands with that verb Get-Verb | Get-Random | Get-Command
-------------------------- EXAMPLE 3 -------------------------- Get-Verb "S*"
Command Parameters:
Name Description verb The verb names to filter on (optional)
Here’s Get-Verb:
function Get-Verb { <# .Synopsis Gets the standard PowerShell verbs .Description Uses reflection to get the standard PowerShell verbs and return them as a property bag .Parameter verb The verb names to filter on (optional) .Example # Gets all verbs Get-Verb .Example # Gets a random verb and searches for commands with that verb Get-Verb | Get-Random | Get-Command .Example Get-Verb "S*" #> param( [Parameter(ValueFromPipeline=$true,Position=0)] [string[]] $verb = "*" ) begin { $allVerbs = [PSObject].Assembly.GetTypes() | Where-Object {$_.Name -like "*Verbs*"} | Get-Member -type Property -static | Select-Object @{ Name='Verb' Expression = {$_.Name} }, @{ Name='Group' Expression = { $str = "$($_.TypeName)" $str.Substring($str.LastIndexOf("Verbs") + 5) } }, @{ Name='Type' Expression = { $_.TypeName -as [Type] } } } process { foreach ($v in $verb) { $allVerbs | Where-Object { $_.Verb -like $v } } } }
Automatically generated with Write-CommandBlogPost
0 comments