Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to collect a Verbose stream from a parent-child powershell script from .NET?
    primarykey
    data
    text
    <p>I have: C#.NET using the PowerShell() object, calling one powershell script, which calls another.</p> <p>C#->Powershell(parent)->Powershell(child). [capture verbose: parent works, child does not].</p> <p>My code CORRECTLY grabs/streams Verbose from the first (parent) powershell script. However, I have not been able to get the Verbose stream from the (child) powershell script. Note: if I call hello1.ps directly, it works (because it's not the child).</p> <p>(I've read numerous articles / searches / other stackoverflow answers. Mostly they talk about how to capture it once, or recommend the `$verbosepreference). </p> <p>Solutions? Thanks!</p> <pre><code> public void Run() { var ps = PowerShell.Create(); ps.AddScript("`$verbosepreference='continue'"); // &lt;-- tried this, no effect. ps.AddScript("set-location \"" + dir + "\""); ps.AddScript(System.IO.File.ReadAllText("./hello-caller.ps1")); ps.AddParameter("name", "A"); ps.AddParameter("where", "B"); var output = new PSDataCollection&lt;PSObject&gt;(); output.DataAdded += Verbose_DataAdded; var results = ps.BeginInvoke&lt;PSObject, PSObject&gt;(null, output, null, AsyncInvoke, null); } void Verbose_DataAdded(object sender, DataAddedEventArgs e) { var source = ((PSDataCollection&lt;PSObject&gt;) sender); var msg = source[e.Index].ToString(); Console.WriteLine(msg); } --- hello-caller.ps1 --- Param( [string]$name, [string]$where ) ./hello.ps1 $name $where --- hello.ps1 --- Param( [string]$name, [string]$where ) $i = 0 while ($i -le 30) { Write-Verbose "Hello " $name " from " $where Start-Sleep -s 1 $i++ } return true </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload