Powershell Best Practice #17: Use the same parameter name than the native one

Best Practice: It is recommended to use the same name for your parameter (for your functions) than the native one parameter of the builtin Powershell cmdlets.

Explanation:

If you create a function which takes as a parameter a computerName, you should use the name : ComputerNameWhy “ComputerName”? Because many builtin cmdlets use this parameter name so you should follow this standard.

PowerShell

1

2

3

4

5

6

# Recommended

Get-InstalledProgram-ComputerName

# Not recommended (because the name is not -ComputerName)

Get-InstalledProgram-Computer

Get-InstalledProgram-Server

However, you can use alias to handle these non-native parameters names (ex: Server, Computer, etc.)

PowerShell

1

2

3

4

5

6

7

8

functionGet-InstalledProgram

{

Param

(

[Alias("Server","Computer")]

[string[]]$ComputerName

)

}

It is useful to improve the readability and the understanding, if your parameter looks like a native one, there is no possible confusion.