Error: A positional parameter cannot be found that accepts argument

Hi everyone,

When i run my script as follows;

Get-Printer “localhost” $FaturaPrinterName | Remove-PrinterPermission “everyone”

I am getting the below error.

Get-Printer : A positional parameter cannot be found that accepts argument ‘ATURA-KH11_1’.
At line:266 char:1

  • Get-Printer “localhost” $FaturaPrinterName | Remove-PrinterPermission …
  •   + CategoryInfo          : InvalidArgument: (:) [Get-Printer], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Get-Printer
    
    

However when i run my script a second time, it gives me no error. But it is important to me that my script should run at first time

Is there anyone who help me?

Mostly it is helpful to read the help. :wink: Get-Printer only has one positional parameter - “-Name”. But you could make your live easier and simply use the parameter names!

This is specifically because the way you are calling this is not correct and really should always fail the way you have this.
So, the second call having success is a bit odd.

The help files specifically state that the only possible parameters are

((Get-Command -Name Get-Printer).Parameters).Keys

Name
ComputerName
Full
CimSession
ThrottleLimit
AsJob
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable

More help seen here

Get-Help -Name Get-Printer -Full
Get-Help -Name Get-Printer -Examples

Yes you are right to use get printer normally however i have this script as follows to set printer permissions.

# function get the list (List) ACL printer or all Printer 
function Get-Printer ($Computer = ".", $name) {
    # If the variable $name is empty, it returns a list of all local printers 
    if ($name) {
        $Printers = gwmi Win32_Printer -ComputerName $Computer -Filter "name = '$name'"
    } else {
        $Printers = gwmi Win32_Printer -ComputerName $Computer -Filter "local = '$True'"
    }
    # array declaration lists ACL 
    $PrinterInfo = @()
    # Retrieve the ACL of each element of the array of lists ACL 
    foreach ($Printer in $Printers) {
        if ($printer) {
            # the variable $SD obtain the security descriptor for each printer and each element of the ACE (DACL) 
			# And add $PrinterInfo 
            $SD = $Printer.GetSecurityDescriptor()
            $PrinterInfo += $SD.Descriptor.DACL | %{
                $_ | Select @{e = {$Printer.SystemName}; n = 'Computer'},
                @{e = {$Printer.name}; n = 'Name'},
                AccessMask,
                AceFlags,
                AceType,
                @{e = {$_.trustee.Name}; n = 'User'},
                @{e = {$_.trustee.Domain}; n = 'Domain'},
                @{e = {$_.trustee.SIDString}; n = 'SID'}
            }
        } else {
            Write-Warning "Specified printer not found!"
        }
    }
    # Giving information about the ACL on the yield function for subsequent submission to the conveyor 
    $PrinterInfo
}

So it works always and sets permissions except first time :slight_smile: This enough for me but i dont want to get this error at first time.

@Postanote you may remember, i asked this before. I am using one of examples which you suggest.

You can see:
https://powershell.org/forums/topic/setting-printer-permissions-by-using-powershell/#post-89008