将参数传递给 PowerShell [英] Passing Arguments to PowerShell

查看:36
本文介绍了将参数传递给 PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 Sub 将参数传递给 Powershell.

I am using following Sub to pass arguments to Powershell.

     Sub testpower()
      Set WshShell = CreateObject("WScript.Shell")
      WshShell.Run ("Powershell.exe -file .\test.ps1 -path ""Shell.txt"" ")
     End Sub

但是,在VB中运行时不会产生输出,但是如果尝试直接从run命令运行,它会给出所需的结果.请帮忙.

But,the output is not generated when run in VB,but if try to run directly from run command,it gives the desired result.Please help.

test.ps1 脚本:

test.ps1 script:

 Param([String]$path)
    Get-AuthenticodeSignature $path | Out-File  "C:\Documents and Settings\acmeuser1\output.txt"

推荐答案

这个问题基本上在 用于捕获标准输出的 VBscript 代码,而不显示控制台窗口 - 那里有几种技术可以说是有效的.总而言之,使用 WShell.Exec 而不是 WShell.Run,然后通过 WShell.StdOut.ReadLine() 捕获输出>WShell.StdOut.ReadAll().

This question is essentially answered in VBscript code to capture stdout, without showing console window - there are several techniques there that are stated as working. To summarize, use WShell.Exec instead of WShell.Run, and then capture the output via WShell.StdOut.ReadLine() or WShell.StdOut.ReadAll().

这篇关于将参数传递给 PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆