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!
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
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.