将参数传递给PowerShell

问题描述:

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

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

但是,在VB运行时不会产生输出,但如果试图直接从运行命令来运行,它给所需result.Please帮助。

test.ps1脚本:

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

您是否尝试过使用文件的完整路径名? –

+0

是的,我试过两种方法.. – abhinov

+0

这有点奇怪,因为它为我工作。运行脚本后是否创建了C:\ Documents and Settings \ acmeuser1 \ output.txt文件?您是否尝试向Get-AuthenticodeSignature的输出输出其他内容? –

这个问题基本上回答VBscript code to capture stdout, without showing console window - 有几个技术有被表述为工作。总而言之,使用WShell.Exec而不是WShell.Run,然后通过WShell.StdOut.ReadLine()WShell.StdOut.ReadAll()捕获输出。