从PowerShell脚本执行.vbs不起作用,但是从PowerShell命令行运行.vbs可以

时间:2018-10-26 20:11:44

标签: powershell vbscript

我正在尝试编写PowerShell脚本,该脚本最终将用作某些硬件的测试自动化,这些硬件使用网络交换机将电源切换到远程系统。

可以通过本地telnet端口接口访问网络交换机。

我的PowerShell脚本实现如下所示:

C:\dev\ruby\zzz-5.2.1>bundle exec rake test Run options: --seed 11056 # Running: ....*** 128 *** *** 0 *** ... Finished in 1.576030s, 4.4415 runs/s, 5.7106 assertions/s. 7 runs, 9 assertions, 0 failures, 0 errors, 0 skips

test.ps1

Start-Process -FilePath "C:\Windows\System32\cscript.exe" -ArgumentList "C:\<path_to_file>\off.vbs"; Start-Sleep -s 10; # wait 10 seconds so that hardware powers down completely Start-Process -FilePath "C:\Windows\System32\cscript.exe" -ArgumentList "C:\<path_to_file>\on.vbs";

off.vbs

Set WshShell = CreateObject("WScript.Shell") WshShell.Run "cmd.exe /C" WScript.Sleep 1000 WshShell.SendKeys ("telnet 172.28.104.32{Enter}") WshShell.SendKeys ("pset 4 0{Enter}") WshShell.SendKeys ("logout{Enter}") WScript.Sleep 1000 WScript.Quit

on.vbs

如果我在PowerShell控制台中运行此命令,则可以正常运行

powershell cmd line

但是,如果我运行PowerShell脚本,则看不到任何操作。

编辑:此PC上的控制计算机是普通的Windows 10盒,并且不能使用像腻子或plink这样的新软件,使用内置的Windows可执行文件和某些脚本(安全原因)存在一定的限制

0 个答案:

没有答案
相关问题