Sort alternative as a PowerShell verb?

I have a PowerShell Sort-VersionLabels . When I add this function to the module, the Import-Module complains:

 WARNING: Some imported command names include unapproved verbs which might make them less discoverable. Use the Verbose parameter for more detail or type Get-Verb to see the list of approved verbs. 

According to this , Sort is a "reserved verb."

What could be a good (and approved) alternative?

Update
The function takes an array of version numbers in the form: <major>.<minor>.<revision>[-<milestone[nr]>] . The milestone can be dev , alpha , beta or stable (in that order). Thus, the standard Sort-Object function will not work.

It outputs the sorted array to the pipeline line.

+5
source share
4 answers

The core of this problem will generate stubborn results. This creates a riddle, as you are looking for something specific that the current answers could not answer about. I understand that you are looking for a solution that logically matches your function, being in the standard list of verbs, which is amazing. To continue with an earlier comment, I did to try to indicate a case for all approved verbs that may be appropriate for your situation. I will refer to the list of approved verbs, which is often related to your question, and will use “AVL” for brevity in the future.

  • Group . Comments on AVL relate to using this instead of Arrange. Arranging a synonym for sorting would be nice. Following recommendations, we must use the Group
  • Install . This is a synonym for sorting. However, in AVL, it is associated with Write, Reset, Assign, or Configure, which are not related to your cmdlet. However, it is on the list and can fit if you are ready to give up the discomfort that it creates with existing PowerShell cmdlets.
  • I really don't have number 3.
  • Update . This is a weak case, but AVL refers to its use as a way to maintain [command status] [and] accuracy.
  • Order / Organization . Not in AVL, but I believe that they are very suitable and do not conflict with existing verbs.

Ultimately, AVL will be damned and do whatever you want. Sort very suitable for what you are trying to do. You can also use -DisableNameChecking when importing your module. In the end, this is just a warning. The briatist answer is also good in my opinion.

And I think my English is better than him.

Comment Bonus

Not that you asked him, but when you said that we need to enable name verification, I thought about it. Just for fun!

 $reservedVerbs = "ForEach","Format","Group","Sort","Tee" $approvedVerbList = (Get-Verb).Verb Get-Command -Module Microsoft.WSMan.Management | ForEach-Object{ If ($approvedVerbList -notcontains ($_.Name -split "-")[0]){ Write-Warning "$($_.Name) does not use an approved verb." } If ($reservedVerbs -contains ($_.Name -split "-")[0]){ Write-Warning "$($_.Name) is using a reserved verb." } } 
+4
source

I think something like ConvertTo-SortedVersionLabels , although a bit uncomfortable, uses an approved and not reserved verb, but is still clear.

You can also sort the parameter for another function, for example Get-VersionLabels -Sorted .

How you will work depends on your module as a whole and whether you have such a function to change. This is unclear from your current post, but if you edit it with more details, we can provide more suggestions.

+4
source

Whenever I need a verb that is not an approved PowerShell verb, I use Invoke- * instead. So, in your case, you can call it Invoke-SortVersionLabels

+3
source

You do not need a special cmdlet. If a VersionLabel is an object, just grab the collection and drag it into the Sort-Object using the properties you need.

 # Assuming a versionlabel has a 'Name' Property... $VersionLabelCollection | Sort-Object -Property:Name 
0
source

Source: https://habr.com/ru/post/1207818/


All Articles