Redirect all powershell console message to WDF:textbox

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

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #161456

    Participant
    Topics: 3
    Replies: 4
    Points: 18
    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.

  • #161459

    Participant
    Topics: 3
    Replies: 4
    Points: 18
    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: 999
    Points: 1,946
    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: 3
    Replies: 4
    Points: 18
    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: 23
    Replies: 154
    Points: 367
    Helping Hand
    Rank: 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.

The topic ‘Redirect all powershell console message to WDF:textbox’ is closed to new replies.