Search code examples
windowspowershellscriptingmanpage

Powershell documentation option and required arguments syntax


first question here.

I have essentially the same question as the last part of this (the answer there didn't answer that part):

https://superuser.com/questions/1129307/how-to-read-powershell-documentation-syntax

In short: how do I know which arguments are required vs. optional?

For example, the Copy-Item command:

SYNTAX
    Copy-Item [-Path] <String[]> [[-Destination] <String>] [-Container] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include 
    <String[]>] [-PassThru] [-Recurse] [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]

    Copy-Item [[-Destination] <String>] [-Container] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include <String[]>] [-PassThru] 
    [-Recurse] -LiteralPath <String[]> [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]

Is Destination a required parameter? How would I know that?

Lastly, in general, what is the type of question I am asking called? I tried googling "powershell man pages syntax" and "how to read man pages" (for Unix). Really, I am looking for documentation regarding how they wrote the documentation!

Edit: I found this resource for Unix; something similar for Powershell would be great: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Thanks.


Solution

  • Required arguments do not have the square brackets. If the parameter name does not have square brackets, that needs to be declared with the item as it's not bound by position.

    This is the closest thing I could find regarding help:
    about_Comment_Based_Help

    Additionally, if you use the -online flag with Get-Help, it has very detailed information regarding syntax, parameters, etc. Often with examples.