Update Statusbar for remote PS session

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Update Statusbar for remote PS session

Post by Abhishek_Paul »

  1. $scriptblock = {
  2.  
  3. Write-Output " Step 1 : Completed"
  4.  
  5. #do Some work
  6.  
  7. Write-Output " Step 2 : Completed"
  8.  
  9. #do Some work
  10.  
  11. Write-Output " Step 3 : Completed"
  12.  
  13. #do Some work
  14.  
  15. }
  16.  
  17. $out = Invoke-Command -ComputerName $computerName -Credential $cred
  18.  
  19.  
  20. $statusbar1.Text = $out #Write some working code so that it will update the status bar with each step
I am running this script block on remote computer and want to update the statusbar in GUI with each steps performed on remote machine . Please help me to figure out a way to do that.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Statusbar for remote PS session

Post by jvierra »

You cannot update a local variable from a remove command. YOU can use a job and receive the results using a timer.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Statusbar for remote PS session

Post by jvierra »

You can try this:
  1. Invoke-Command -ScriptBlock $sb -ComputerName $computerName -Credential $cred  |
  2.     ForEach-Object{
  3.          $statusbar1.Text = $_
  4.          [System.Windows.Forms.Application]::DoEvents()
  5.     }
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Re: Update Statusbar for remote PS session

Post by Abhishek_Paul »

jvierra wrote:You can try this:
  1. Invoke-Command -ScriptBlock $sb -ComputerName $computerName -Credential $cred  |
  2.     ForEach-Object{
  3.          $statusbar1.Text = $_
  4.          [System.Windows.Forms.Application]::DoEvents()
  5.     }
I get nothing in statusbar .
I understand that we can get output from remote Ps-Session and save the result locally . With the same logic we can save the result to a variable and feed it ti statusbar1.text .

With the solution provided by you , we need to tweak something to get the result .I believe it's possible.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Statusbar for remote PS session

Post by jvierra »

Whether it works at all depends on what you are outputting and how you are outputting it.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Statusbar for remote PS session

Post by jvierra »

This works perfectly for me:
Attachments
Test-WordHosting.psf
(13.36 KiB) Downloaded 109 times
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Re: Update Statusbar for remote PS session

Post by Abhishek_Paul »

jvierra wrote:This works perfectly for me:
I was doing a silly mistake.
Thanks a billion Jvierra ... :) You are awesome as always.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Statusbar for remote PS session

Post by jvierra »

We all love silly mistakes as long as we can find them. Glad you found it.

Thanks for the compliment.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked