WMI可以做到这一点,但我有一个问题,PC已启用,但已注销。如果我试着跑:
wmic /node:%strIP% printer where DeviceID="lp1" set DriverName="Lexmark Universal v2"
它失败并显示有关"泛型失败的消息"。我在RDP中然后从我的结束运行相同的命令,它的工作原理。我使用的Powershell版本较旧,因此它没有一些打印机cmdlet,并且更新PS目前是不可能的。有没有办法远程登录某人,而无需实际使用RDP?通过PS,cmd,PSEXEC等?
我采取的另一种途径是使用注册表,但是我正在尝试使用注册表,即我无法弄清楚要复制的内容。在注册表中,我可以更改drivername和启用双面打印和托盘2的设置(在打印机设置中),但我无法想象如何更改打印机首选项中的设置以进行双面打印并沿着长边进行打印。
我做了什么来弄清楚要改变什么,我在regedit中找到了打印机名称作为数据值并在更改设置之前导出了键。然后我在更改设置后再次导出它。然后我使用fc /c /a /u before.reg after.reg
来获取更改。我砍掉.reg只包含更改的值。运行.reg似乎改变了一切,但沿着长边设置打印两面。它是一个lexmark打印机,所以我想知道它的偏好是否存储在其他地方。
这是我最新的PS1脚本。当我尝试不同的做事方式时,我已经注释了一些内容:
$Cred = Get-Credential
$Str = Read-Host "Please select a site ID [###] "
$PC = Read-Host "Please select a PC number [##] "
Clear-Host
$PCNm = "$Str-CCPC-$PC"
function Test-PsRemoting
{
try
{
$errorActionPreference = "Stop"
$result = Invoke-Command -ComputerName $PCNm { 1 }
}
catch
{
Write-Verbose $_
return $false
}
if($result -ne 1)
{
Write-Verbose "Remoting to $PCNm returned an unexpected result."
return $false
}
$true
}
If(!(Test-PsRemoting)){
PSEXEC \\$PCNm powershell Enable-PSRemoting -force 2>&1 >nul
Clear-Host
Write-Host "Enabled PsRemoting"
}else{Write-Host "PsRemoting already enabled"}
Invoke-Command -ComputerName $PCNm -Credential $Cred -ScriptBlock {
#$lp1 = Get-WMIObject -Query "SELECT * from Win32_Printer Where DeviceID='lp1'"
$lp1 = Get-WmiObject Win32_Printer | ?{$_.name -eq "lp1"}
$lp1.Scope.Options.EnablePrivileges = $true
$lp1.DriverName = "Lexmark Universal v2"
$lp1R = $lp1.Put()
#$lp2 = Get-WMIObject -Query "SELECT * from Win32_Printer Where DeviceID='lp2'"
$lp2 = Get-WmiObject Win32_Printer | ?{$_.name -eq "lp2"}
$lp2.Scope.Options.EnablePrivileges = $true
$lp2.DriverName = "Lexmark Universal v2"
$lp2R = $lp2.Put()
}
#$lp1 = Get-WMIObject -Impersonation Delegate -Authentication Call -Credential $Cred -ComputerName $PCNm -Query "SELECT * from Win32_Printer Where DeviceID='lp1'"
#$lp1.DriverName = "Lexmark Universal v2"
#$lp1.Put()
无论我尝试哪种方式,invoke-command或get-wmiobject,我都会:
Exception calling "Put" with "0" argument(s): "Generic failure "
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
+ PSComputerName : 150-CCPC-02
答案 0 :(得分:0)
这并没有特别回答你的实际问题,但作为我如何做同样事情的解决方案我想我会把你扔到一起来更新打印机属性。当我从创建打印机功能移植它时,我根本没有清理过这个。
Function Set-SSPrinter {
Param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[ValidateNotNullOrEmpty()]
[string]$ComputerName,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Name,
[string]$PortName,
[string]$DriverName,
[string]$Comment,
[string]$Location,
[bool]$Shared,
[string]$ShareName = $Name,
[string]$PermissionSDDL,
[string]$PrintProcessor,
[string]$DataType,
[bool]$RawOnly
)
try {
$modprinter = Get-WmiObject Win32_Printer -ComputerName $ComputerName | ?{$_.name -eq $Name}
$modprinter.Scope.Options.EnablePrivileges = $true
if($DriverName) {
$modprinter.DriverName = $DriverName
}
if($PortName) {
$modprinter.PortName = $PortName
}
if($Shared) {
$modprinter.Shared = $Shared
}
if($ShareName) {
$modprinter.ShareName = $ShareName
}
if($Location) {
$modprinter.Location = $Location
}
if($Comment) {
$modprinter.Comment = $Comment
}
if($Name) {
$modprinter.DeviceID = $Name
}
if($PrintProcessor) {
$modprinter.PrintProcessor = $PrintProcessor
}
if($DataType) {
$modprinter.PrintJobDataType = $DataType
}
if($RawOnly) {
$modprinter.RawOnly = $RawOnly
}
$result = $modprinter.Put()
if($PermissionSDDL) {
$modprinter.SetSecurityDescriptor($objHelper.SDDLToWin32SD($PermissionSDDL).Descriptor) | Out-Null
}
$("Update Complete: " + $Name)
} catch {
$("Update Failed: " + $Name)
Write-Warning $_.Exception.Message
$error.Clear()
}
}
不幸的是,我使用打印机名称来确定要在远程计算机上修改哪个设备。您从已打开的PowerShell会话执行的凭据必须具有远程计算机的管理员权限。如有必要,请在powershell.exe上运行不同的用户
使用示例:
Set-SSPrinter -ComputerName "10.210.20.100" -Name "TestPrinter" -DriverName "Lexmark Universal v2"
答案 1 :(得分:0)
wmic /node:servername /user:username /password:password path win32_something call methodname
该怎么做。
用户最好使用登录脚本,因为这就是Windows的设计方式。