AdsiPS icon indicating copy to clipboard operation
AdsiPS copied to clipboard

Get-ADSIComputer $ComputerName

Open lazywinadmin opened this issue 9 years ago • 1 comments

When using Get-ADSIComputer $ComputerName

I'm getting the following error

Get-AdsiComputer $env:COMPUTERNAME Get-ADSIComputer : A positional parameter cannot be found that accepts argument '<NAME OF COMPUTER>'. At line:1 char:1

  • Get-AdsiComputer $env:COMPUTERNAME
  •   + CategoryInfo          : InvalidArgument: (:) [Get-ADSIComputer], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Get-ADSIComputer
    

lazywinadmin avatar Nov 01 '16 21:11 lazywinadmin

The error is due to not listing a position for any of the parameters in the function. You mention in your guidelines to use explicit parameter names and not assume position, which is good, but if you don't have position set for any of the parameters, you prevent the use of your function without explicitly naming the parameters when calling it.

So you either need to always use named parameters: Get-ADSIComputer -Identity $env:COMPUTERNAME

Or adjust the $Identity parameter line to allow it to accept positional input: param ([Parameter(Mandatory=$true,Position=0,ParameterSetName="Identity")])

Get-Ryan avatar May 23 '17 13:05 Get-Ryan