问题
How do you disable 'Bidirectional communication' using powershell?
I can see EnableBIDI
when running:
get-WmiObject -class Win32_printer | fl *
But when I try this, it says the property was not found?
Set-PrinterProperty -PrinterName "Some Printer" -PropertyName "EnableBIDI" -Value $False
回答1:
You are mixing properties from two different WMI classes. Set-PrinterProperty manipulates instances of the undocumented MSFT_PrinterProperty
class from the root/standardcimv2
namespace, which has different properties than the Win32_Printer class in your previous command.
Instead, manipulate the desired instance of the Win32_Printer
class since that has the property you want, then call Put() to commit the change. This works for me when run with elevation:
$printer = Get-WmiObject -Class 'Win32_Printer' -Filter 'Name = ''My Printer Name'''
$printer.EnableBIDI = $false
$printer.Put()
Using the newer CimCmdlets module you can make that change in similar fashion using the Get-CimInstance and Set-CimInstance cmdlets...
$printer = Get-CimInstance -ClassName 'Win32_Printer' -Filter 'Name = ''My Printer Name'''
$printer.EnableBIDI = $false
Set-CimInstance -InputObject $printer
...or simplify it to a single pipeline...
Get-CimInstance -ClassName 'Win32_Printer' -Filter 'Name = ''My Printer Name''' `
| Set-CimInstance -Property @{ EnableBIDI = $false }
...or even simplify it to a single cmdlet invocation...
Set-CimInstance -Query 'SELECT * FROM Win32_Printer WHERE Name = ''My Printer Name''' -Property @{ EnableBIDI = $false }
来源:https://stackoverflow.com/questions/48992474/disable-bidirectional-communication-for-a-printer