Page 1 of 2

Powershell Studio 2015 visual indicator update real time?

Posted: Wed Feb 10, 2016 5:16 am
by stratagem
Sorry for the poor subject line. I'm not sure how to word it exactly.

What I'd like to do is create some visual indicators for the users showing if a service is running or not. Maybe change a label box or picture box to red / green depending on the status? Is it possible to have this job running in the background separate from the button clicks and have it update the boxes in real time?

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Wed Feb 10, 2016 7:22 am
by jvierra
Yes - You can use a timer tick to do this.

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Wed Feb 10, 2016 9:06 am
by stratagem
Thanks! I'll read more on timers.

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Thu Feb 11, 2016 8:50 am
by stratagem
I'm having a hard time working this out.

Would it be best to create this function, if it should be a function, in the form_load section or before that? And then have a function for each label call on the timer?

Sorry, I'm still learning Powershell and most of my scripts have been one-liners. I still have a long ways to go...

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Thu Feb 11, 2016 9:14 am
by jvierra
Why do you need functions to change a labels color?

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Thu Feb 11, 2016 9:22 am
by stratagem
I'm using this method as feedback for the end users. Right now when I click start or stop it works but it doesn't provide any indication that it's finished. So the user has to trust that it is working and remember which services they have either started or stopped.

Functions might not be what I need. I'm unsure on how to solve this problem.

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Thu Feb 11, 2016 11:50 am
by jvierra
What does that have to d with functions.

You are way too vague for me to be able to answer. What are you doing? What and how many services? What is the purpose?

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Thu Feb 11, 2016 1:10 pm
by jvierra
You asked bout timers. What do the timer and the button have to do with each other?

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Fri Feb 12, 2016 4:56 am
by stratagem
Sorry, not trying to be vague.

It's a small form that stop/starts about 15 different services spread over 3 different servers. The labels themselves are only there to show if the service is running. That's it.

So something like this...

If ($Service.Status -eq "Running")
{
$label1.Text = "Running"

}
Else { $label1.Text = "Stopped" }

}

I need it on a timer or something else that will automatically update the labels every X amount of seconds.
Hopefully that clears it up.

Re: Powershell Studio 2015 visual indicator update real time?

Posted: Fri Feb 12, 2016 5:18 am
by jvierra
Here is an easier way to handle that..
  1. $timer_tick={
  2.     $services= 'service1', 'service2', 'service3'
  3.     $services=$computers|
  4.         ForEach-Object{
  5.             Get-Service -Computer $_ -Name $services
  6.         } |
  7.     select MachineName,DisplayName, Status
  8.  
  9.     $datagridview.DataSource=[collections.arraylist]$services
  10. }
We can also use a list view with images or a checked listbox.