繁体   English   中英

调用powershell脚本后,批处理文件不会继续

[英]Batch file wont continue after call up a powershell script

我有一个情况。 我正在使用调用Powershell脚本的批处理文件在远程桌面上安装网络打印机,但是在远程桌面上安装打印机之后,Powershell什么也没有返回 - 所以我的批处理文件将无法继续...我必须手动命中输入两次以使其echo DONE并运行其余脚本。 知道为什么吗?

@echo off

Copy /Y "\\AddPrinter\AddPrinter.ps1" "C:\scripts" 

powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1" 

Echo DONE

Del /F /Q "C:\ntfs3\scripts\AddPrinter.ps1"

这是我的powershell脚本,我甚至在脚本的末尾放了一个exit ,但是远程PC上的powershell只是不会退出.....所以它不会返回批处理

$PrinterPath = "\\server-01\Printer0101"
$net = new-Object -com WScript.Network
$net.AddWindowsPrinterConnection($PrinterPath)
exit

顺便说一句,我使用psexec调用这个批处理文件,其中包含一个包含所有pc名称的txt文件。

psexec @%1 -u admin -p xxxxxx -c -f "C:\AAA\AddPrinter.bat"

我做了一些研究,有人说需要使用%1 > null call来使Powershell返回批处理。 但它也不起作用。

Call powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1"  %1 > null

我只能使用批处理命令安装打印机,但安装后,新打印机始终设置为默认打印机。 但如果使用powershell安装它,它不会更改远程桌面上的默认打印机。

rundll32 printui.dll PrintUIEntry /ga /n\\server-01\printer0101

请提示。

我经常看到通过psexec.exe调用PowerShell的问题。 我建议放弃psexec.exe并配置PowerShell Remoting。 然后,您可以使用Invoke-Command命令部署脚本。

我也建议使用DOS命令来使用invoke-expression PowerShell将按原样处理您传递的命令。 伟大的是你将能够传递变量

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM