- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 PowerShell 在 Windows 2012 R2 中设置默认打印机。每当我在本地执行此操作时,它都可以正常工作,但是无论我如何尝试远程运行它(我需要这样做),它总是会失败并出现以下错误。我已经尝试使用域管理员帐户以及我需要为其更改默认打印机的用户凭据,但它仍然失败。
Exception calling "SetDefaultPrinter" : "Not supported " At line:1 char:1 + (Get-WmiObject -Class Win32_Printer -Filter "(Name='Microsoft XPS Document Write ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WMIMethodException
$Printer = Get-WmiObject -Class Win32_Printer -Filter "(Name='Microsoft XPS Document Writer')"
$Printer.SetDefaultPrinter()
$Printer = Get-WmiObject -ComputerName "MyRemoteComputer" -Class Win32_Printer -Filter "(Name='Microsoft XPS Document Writer')"
$Printer.SetDefaultPrinter()
Invoke-Command -ComputerName "MyRemoteComputer" -ScriptBlock {(Get-WmiObject -Class Win32_Printer -Filter "(Name='Microsoft XPS Document Writer')").SetDefaultPrinter()}
Get-WmiObject -ComputerName "MyRemoteComputer" -Class Win32_Printer -Filter "(Name='Microsoft XPS Document Writer')" | Invoke-WmiMethod -Name 'SetDefaultPrinter'
非常感谢任何帮助和指导。
最佳答案
继续搜索后,我终于找到了一个可用的版本。我不完全明白为什么,但它有效,这对我来说已经足够了。幸运的是,我已经在代码的前面访问了用户名和密码,否则它仍然可以使用 Get-Credential
:
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "DOMAIN\Username", (ConvertTo-SecureString -String "ClearTextPassword" -AsPlainText -Force)
Invoke-Command -ComputerName "MyRemoteComputer" -Credential $Credential -ScriptBlock {
$net = new-Object -com WScript.Network
$net.SetDefaultPrinter("Microsoft XPS Document Writer")
}
关于windows - 通过 Get-WmiObject : Exception calling SetDefaultPrinter : Not Supported 设置默认打印机时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42487713/
概览 我正在尝试使用 PowerShell 在 Windows 2012 R2 中设置默认打印机。每当我在本地执行此操作时,它都可以正常工作,但是无论我如何尝试远程运行它(我需要这样做),它总是会失败
我是一名优秀的程序员,十分优秀!