Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun – Test PowerShell Command Name

Posted on October 12, 2012September 13, 2013

Earlier this week I exchanged a few tweets with @jonhtyler about coming up with a proper name for a PowerShell function he was developing. The suggested best practice is to use the Verb-Noun naming convention, using an accepted verb. You can see the verbs with the Get-Verb cmdlet. So I figured why not automate this a bit. After all, sometimes it can be tricky finding the proper verb. Sometimes it helps to actually see the name first. So I put together this simple function called Test-CommandName.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Function Test-CommandName {

#comment help is here

Param(
[Parameter(Position=0,Mandatory=$True,
HelpMessage="What is the noun for your command?")]
[ValidateNotNullorEmpty()]
[string]$Noun,
[ValidateSet("All","Common","Data","Lifecycle","Diagnostic","Communications","Security","Other")]
[string]$Category="All"

)

if ($Category -eq "All") {
#get all verb names and add to an array
$verbs = Get-Verb | Select -ExpandProperty Verb
}
else {
#get verbs that belong to the given category and add to an array of verb names
$verbs = Get-Verb | Where {$_.Group -eq $Category} | Select -ExpandProperty Verb
}

foreach ($verb in $verbs) {
<#
go through each verb and display a string that
represents a potential Verb-Noun name for
your command
#>

"{0}-{1}" -f $verb,$noun
}

} #end Test-CommandName function

The function takes the noun you want to use as a parameter. By default, the function will combine it with all possible verbs and write a string with each file name to the pipeline. But you can specify a verb category if you want. Notice the use of the ValidateSet decorator. The rest of the code is commented and should be pretty easy to follow. But now I can do something like this:

PS C:\> Test-CommandName -Noun DataFile -Category Data
Backup-DataFile
Checkpoint-DataFile
Compare-DataFile
Compress-DataFile
Convert-DataFile
ConvertFrom-DataFile
ConvertTo-DataFile
Dismount-DataFile
Edit-DataFile
Expand-DataFile
Export-DataFile
Group-DataFile
Import-DataFile
Initialize-DataFile
Limit-DataFile
Merge-DataFile
Mount-DataFile
Out-DataFile
Publish-DataFile
Restore-DataFile
Save-DataFile
Sync-DataFile
Unpublish-DataFile
Update-DataFile

Just a little PowerShell Friday Fun, but maybe you'll pick up a tip or two. Download Test-CommandName and let me know what you think. The download version includes comment based help and should work in PowerShell v2 or v3.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d