Link to home
Start Free TrialLog in
Avatar of D B
D BFlag for United States of America

asked on

PowerShell - Tell if a Server is Online or Disconnected

I am creating a PowerShell script that can be run interactively on a server, but it is also possible that the user can disconnect from the machine while the script is executing. Before displaying a messagebox, I'd like to know whether the user is logged in (and display the messagebox) or if the account is running disconnected, and write a log message in lieu of a messagebox. Can this be done?
Avatar of D B
D B
Flag of United States of America image

ASKER

FYI, I am wanting to test if the user who started the script is disconnected, not just get a list of disconnected users, etc.
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D B

ASKER

Not exactly sure what to do here. I tried running this code but didn't seem to get any output.
I've got a userid stored in a variable $activeUser. I just want to determine if that user is logged on or disconnected. It would be a domain account on the server that I am testing.
Avatar of D B

ASKER

never mind. for some reason I was not seeing the output.
Can you tell me how I would filter this to get just the State for a specific user? I've been playing around with it and either get an error or no output.
Avatar of D B

ASKER

or all records.
Are you familiar with filtering by using Where-Object?
Avatar of D B

ASKER

To some extent, but only in the context that I've seen it used in some examples. I tried using it but apparently don't know the exact syntax because I am still getting all users, or a syntax error.

For my purpose, all I want to do is return the state for a specific user. Possibly a function where I pass a user and return the state.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D B

ASKER

Got it to work. I've done some phenominal stuff with PowerShell, but still pretty much a newbie. I find what I need to get by on the web and get it to work, and usually can figure it out without asking, but once in a while come across a roadblock. Wish I had time to just deep-dive into it because I have a feeling I'd be even more amazed at what it can do.
Thanks again. Don't spend all the points in one place :-D
There's definitely a lot of capability.  Once you get good at the basics (using the pipeline, filtering objects, selecting properties, checking conditions), you can go a long way.  Keep it up!  :)