Welcome to MSDN Blogs Sign in | Join | Help

Get-Verb

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

Published Friday, January 02, 2009 9:35 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker