$i=0;
$pnp = pnputil -e;$matched = [regex]::matches($pnp, ".......................................Lexmark International");
$split = $matched -split (".........inf");
$replace = $split -replace " Driver package provider : Lexmark International","";
$replace1 = $replace -replace " ","`n";
write-output $replace1;
foreach ($i in $replace1){;
$pnpdel = pnputil -f -d $i;$pnpdel;
};
Reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\Lexmark Universal v2 XL" /f;
net stop spooler;
net start spooler;
$PrinterPath = "\\officechicprt5\111w-2w-bprn-07";
$net = new-Object -Com WScript.Network;
$net.AddWindowsPrinterConnection($PrinterPath)我知道它不漂亮,但每次我试一次,它都会起作用。如果您好奇的话,在我们的环境中,Lexmark驱动程序经常损坏,这实际上是微软的一个问题。在注册表中,依赖文件被截断,因此打印机将永远不会打印,通常迫使打印机胡乱使用。我们找到解决这个问题的唯一方法是完全删除驱动程序,并读取我们的要点并打印驱动程序。这个脚本可以做到这一点,但不幸的是需要UAC的提升。我尝试使用bat文件与以下内容一起运行:
@ECHO OFF
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
timeout /t 10但不幸的是,它给用户留下了一个混乱的表达式和一个UAC提示符。是否可以在bat文件中以某种方式通过PSexec运行此操作?我不想通过RDP将其运行到数百台机器中(在那里,这样做了)。我想要一个可重复的过程,这个问题在这里是一个大流行病。
再次感谢
发布于 2015-06-01 11:47:21
你让事情变得太复杂了。不要用参数启动PowerShell来启动PowerShell。只需直接使用参数启动PowerShell。
powershell.exe -NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1"" -Verb RunAs如果您需要以提升的权限运行PowerShell脚本,当您的用户不是管理员组的成员时,您应该启用PS远程处理并通过Invoke-Command在远程主机上运行它:
Invoke-Command -Computer 'hostA', 'hostB', ... -ScriptBlock {
# your PowerShell code here
}https://stackoverflow.com/questions/30572495
复制相似问题