Redirect all powershell console message to WDF:textbox

Welcome Forums General PowerShell Q&A Redirect all powershell console message to WDF:textbox

Viewing 4 reply threads
  • Author
    Posts
    • #161456
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

      Need help with redirection of all output of script to textbox.

      Example result from script that display in the console:

      Pin-App “Word”
      Pin-App “Google Chrome”
      App ‘Word’ pinned to Start
      App ‘Google Chrome’ pinned to Start

      I want this display in the text box.

      <script src=”https://gist.github.com/tuannguyen778/79b060456cd8ae51aecc18feb0087881.js”></script&gt;

    • #161459
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

      I think i found a solution to redirect all the file using write-out and >> to a file then read it in text box but it only output the result after the script finish running. Anyway to output in real time to the textbox?

    • #161465
      Participant
      Topics: 2
      Replies: 1013
      Points: 2,093
      Helping Hand
      Rank: Community Hero
      1. What do you mean by real time?
      2. Are you saying , that if you send your output to a variable, you cannot get it into the text box?
      3. Why are you popping a console for a GUI app to get data, vs just running the code and using only your GUI?

      Anyway, there are many examples all over the web on how to send output to a form textbox. Two resources / with sample code are here:

      https://learn-powershell.net/2012/11/09/powershell-and-wpf-textbox
      https://learn-powershell.net/2012/11/14/powershell-and-wpf-textblock

       

    • #161468
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member
      1. What do you mean by real time?
      2. Are you saying , that if you send your output to a variable, you cannot get it into the text box?
      3. Why are you popping a console for a GUI app to get data, vs just running the code and using only your GUI?

      Anyway, there are many examples all over the web on how to send output to a form textbox. Two resources / with sample code are here:

      https://learn-powershell.net/2012/11/09/powershell-and-wpf-textbox

      https://learn-powershell.net/2012/11/14/powershell-and-wpf-textblock

      I am not popping a console for my GUI. What I am asking is the output of like Write-Host written to a textbox. My current method is using Write-Output to a file then read that file in the textbox. However that is not real time. There is no console involve.

    • #161594
      Participant
      Topics: 24
      Replies: 175
      Points: 588
      Helping Hand
      Rank: Major Contributor

      There are a few approaches to populating a textbox, you’re running into the standard issue where while a script is running, your forms become unresponsive.
      you have a few choices, background jobs is one approach, there were a number of articles on sapiens forums walking through various approaches.

      PowerShell Studio: Creating Responsive Forms

      heres the first one i could find.

      in general your form will be non-responsive the entire time a block of code is executed locally.

Viewing 4 reply threads
  • The topic ‘Redirect all powershell console message to WDF:textbox’ is closed to new replies.