powershell - 使用 Powershell 在远程计算机上使用返回值调用 VBScript

标签 powershell scripting vbscript

我需要从 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/

相关文章:

动态定义静态定义函数列表的 Pythonic 优雅方式?

user-interface - .hta 文件是一个好的选择吗?

vbscript - 检查文件夹中是否存在任何文件 (VBScript)

powershell - Outlook PowerShell 脚本无法检索最新电子邮件

json - PowerShell解析Json文件

windows - 如何在 Windows 命令行上使用单个命令创建多个文件?

Linux 执行脚本

python - 通过 Python 脚本更改提示工作目录

web-services - 使用 New-WebServiceProxy 在 PowerShell 中添加自定义 SOAP header

VBScript 运行时错误 : ActiveX component can't create object: 'XStandard.MD5'