简体   繁体   English

将参数传递给PowerShell

[英]Passing Arguments to PowerShell

I am using following Sub to pass arguments to Powershell. 我正在使用以下Sub将参数传递给Powershell。

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

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. 但是,在VB中运行时不会生成输出,但是如果尝试直接从run命令运行,则会产生所需的结果。请提供帮助。

test.ps1 script: test.ps1脚本:

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

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. 从本质上讲,此问题已在VBscript代码中得到了回答, 以捕获stdout,而没有显示控制台窗口 -那里说有几种有效的技术。 To summarize, use WShell.Exec instead of WShell.Run , and then capture the output via WShell.StdOut.ReadLine() or WShell.StdOut.ReadAll() . 总而言之,请使用WShell.Exec而不是WShell.Run ,然后通过WShell.StdOut.ReadLine()WShell.StdOut.ReadAll()捕获输出。

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

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