Author Posts

December 16, 2017 at 3:26 pm

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?

December 16, 2017 at 11:22 pm

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

December 16, 2017 at 11:33 pm

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

December 19, 2017 at 7:56 am

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 🙂 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:

Setting Printer Permissions by Using Powershell