我需要从 Powershell 调用远程 VB 脚本,并且 VB 脚本需要在远程机器上运行。
我一直在使用\$computer\root\cimv2:Win32_Process").Create(C:\test.vbs)
这行得通,但是我无法从脚本中获取返回值,只能从 win32 进程中获取返回值。
我会把整个东西都转换成 powershell,但不能,因为我连接到一个遗留域,我不能在上面安装额外的工具,所以必须调用远程 vbscript
最佳答案
这是一个老问题,但我想分享我的解决方案。它与 Ansgar 发布的相同,但已经过测试并且工作正常:
$VNC = '\\share\software\AppName\_Install_Silent.vbs'
$Computer = 'RemoteHost'
$TMP = "\\$Computer\c$\TEMP"
if (!(Test-Path $TMP)) {
New-Item -Path $TMP -ItemType Directory
}
Copy-Item -LiteralPath (Split-Path $VNC -Parent) -Destination $TMP -Container -Recurse -Force -Verbose
$LocalPath = Join-Path 'C:\TEMP' (Join-Path (Split-Path $VNC -Parent | Split-Path -Leaf) (Split-Path $VNC -Leaf))
Invoke-Command -ScriptBlock {cscript.exe $Using:LocalPath} -Computer $Computer
# Restart might be needed of remote host
区别在于您必须先将文件复制到远程机器以避免双跳问题,然后您可以使用 $Using
变量安装它。
希望这对某人有帮助。
关于powershell - 使用 Powershell 在远程计算机上使用返回值调用 VBScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15922055/