【问题标题】:Passing Arguments to PowerShell将参数传递给 PowerShell
【发布时间】:2013-10-03 09:57:39
【问题描述】:

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

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

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

test.ps1 脚本:

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

【问题讨论】:

  • 您是否尝试过使用文件的完整路径名?
  • 是的,我尝试了两种方式..
  • 这有点奇怪,因为它对我有用。运行脚本后是否创建了 C:\Documents and Settings\acmeuser1\output.txt 文件?除了 Get-AuthenticodeSignature 的输出之外,您是否尝试过向其输出其他内容?
  • 我犯了一个错误,它现在对我有用..我想每次都更改路径的值,在这种情况下是“Shell.txt”。如何?
  • 这就是我现在想要做的..Sub testpower() Set WshShell = CreateObject("WScript.Shell") k = Chr(34) & "C:\Documents and Settings\acmeuser1\ 1.vbs" & Chr(34) 'filepath = "" & "C:\Documents and Settings\acmeuser1\1.vbs" & "" WshShell.Run ("C:\WINDOWS\system32\WindowsPowerShell\v1.0\ Powershell.exe -file test.ps1 -path k ") End Sub

标签: powershell vbscript


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-01
    • 2019-02-09
    • 2022-01-05
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多