test vs confirm, which verb to choose?

Answered test vs confirm, which verb to choose?

  • Wednesday, May 02, 2012 11:09 AM
     
     

    I would like to understand the diffrence between Test and Confirm verbs used by powershell cmdlets.

    If anyone can also present examples that strictly show it, I'll be more than grateful


    What I mean, if I want to check existance of something or correct configuration of it and return true or false which verb is more appropriate?

All Replies

  • Wednesday, May 02, 2012 12:57 PM
     
      Has Code

    Test is used to confirm the existence of or verify a condition, good examples of this are:

    Test-Connection

    PowerShell version of Ping, verifies if a system responds to ping

    Test-Path

    As it says, tests for the existence of an object (file/folder/reg key/...)

    Confirm is used in a different context, whether or not you want a command to execute without prompting. For example:

    Remove-Item $Pathtofileorfolder -Confirm

    Will prompt for confirmation before executing the command.

    So to answer your question at the end, Test is the verb you are looking for.

  • Wednesday, May 02, 2012 1:12 PM
     
     

    I know confirm parameter but official verbs list that can be used with powershell cmdlets contains 'confirm'

    http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.verbslifecycle.confirm(v=vs.85).aspx

    So to be specific, my question is: when to use confirm instead of test? An example would be great

  • Wednesday, May 02, 2012 2:17 PM
    Moderator
     
     

    ?

    Confirm means the action will happen if the user consents.

    Test only shows what would happen without doing it.

    Bill

  • Wednesday, May 02, 2012 2:33 PM
     
     

    I think we're still talking about confirm parameter :)

    You can create cmdlet Test-Something but You can also create cmdlet Confirm-Something (according to official verbs list)

    What I want to know is when it is appropriate to use first and when to use second option

  • Wednesday, May 02, 2012 2:50 PM
    Moderator
     
     Answered

    Hi,

    Confirm is a lifecycle verb, not a common verb. It is not one of the verbs used to define a cmdlet name (these are called common verbs). See the Cmdlet Verbs help topic.

    Bill

  • Wednesday, May 02, 2012 3:03 PM
     
     

    can I ask why? :)

    I just don't get it. Start/Stop are lifecycle verbs and are used for cmdlets (service,process etc.) we also have wait-process, invoke-command
    so why is confirm so specific that 'it is not one of the verbs used to define a cmdlet name' ??

    and if it isn't, why it is on a officiall verbs list?

  • Wednesday, May 02, 2012 3:17 PM
    Moderator
     
     

    Hi,

    That's knowledge to be gained by reading the developer documentation.

    Bill

  • Tuesday, May 08, 2012 1:22 AM
    Moderator
     
     

    Per the link Bill provided, my guess is that Confirm could be used as a verb for a cmdlet, but has not (as yet). Same for Assert and Request in the same category.


    Richard Mueller - MVP Directory Services

  • Tuesday, May 08, 2012 3:25 AM
     
     

    Test - positive assertive action.  "Test your powder before going to battle!"

    Confirm - a query about readiness.  "Please 'confirm' that you have sufficient cajones for the battle ahead"

    Subtle but oh so different.

    Confirm is more likely to be used as a filter.

    dir c:\*.* -recurse | Confirm-Action | Remove-Item

    Kids! Don't try this at home.  The stunts you see here are all done by trained professionals.

    ;)


    ¯\_(ツ)_/¯


  • Monday, May 14, 2012 1:30 AM
    Moderator
     
     

    As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.


    Richard Mueller - MVP Directory Services