Share via


Checking if a Windows server is up and available to logon

Question

Wednesday, March 22, 2017 3:10 PM

I need to check if a Windows Server is up and running and if it is not only powered up but it is available to logon as well.

A possible solution could be attempting to start a RDP session with a fake username and password: if the Windows Server answers "Invalid username" I know it is up and running.

How can I perform such kind of test from inside a PowerShell script?

I downloaded the script on page https://gallery.technet.microsoft.com/scriptcenter/Connect-Mstsc-Open-RDP-2064b10b but it looks too muck complex for my needs.

Is there any alternate or simples solution?

Regards

Mario

All replies (14)

Wednesday, March 22, 2017 5:38 PM | 1 vote

You can't with PowerShell.

You can use Get-Service to retrieve the RDS service from the remote system.

get-service termservice -ComputerName <remote system>

\(ツ)_/


Friday, March 24, 2017 3:18 PM

Thank you for your answer.

I made some tests with no success because I have no user rights on the remote system.

I read your answer to the post on page https://social.technet.microsoft.com/Forums/en-US/24d5c01f-f6b7-4e06-b2e1-7cc16c4f1ad5/remote-getservice-as-normal-user-require-other-privileges?forum=winserverpowershell

Is there any alternate solution I can implement?

Regards

Mario

 


Friday, March 24, 2017 3:55 PM | 1 vote

No.  Not that I know of.

\(ツ)_/


Friday, March 24, 2017 3:57 PM

You could use PortQry to poll the TS port.

\(ツ)_/


Friday, March 24, 2017 4:59 PM

Wouldn't a simple ping command tell you whether its running.. ?


Friday, March 24, 2017 5:15 PM | 1 vote

The following line will tell you who else is logged onto the server.. Correct me if im wrong but using ping to see if server is on and you can talk to it.. then the blow one liner to see if anyone else is logged on :)

query user /server:'ServerName'

Give it a try and let me know how it works and if it solves your issue..

Thanks


Friday, March 24, 2017 6:03 PM | 1 vote

Wouldn't a simple ping command tell you whether its running.. ?

ping may not always work, as firewalls can be configured to block ICMP packets

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''


Monday, March 27, 2017 1:11 PM

Imagine I know the domain Administrator's credentials of the target server, that is member of a domain, while the client is not member of the same domain.

Given that the username is mydomain\administrator and that the password is pa$$w0rd, is there any way to perform the same check by providing the Administrator's credentials?

Regards

Mario

  


Monday, March 27, 2017 4:20 PM

Wouldn't a simple ping command tell you whether its running.. ?

ping may not always work, as firewalls can be configured to block ICMP packets

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

Could you not test this by ensuring the server is on and available manually then ping.. If it doesn't work then you know the firewall is blocking the packets and it works then, it works.. Next time you run it if it doesn't work, that would mean the server is not available wouldn't it.. Or could the firewall block them on a separate basis if they have let them through in the past?


Monday, March 27, 2017 4:36 PM

PortQry will tell you exactly what you wan to know and does not require credentials.

Here is the MS info on this command: https://www.microsoft.com/en-us/download/details.aspx?id=17148

\(ツ)_/


Monday, March 27, 2017 5:25 PM

PortQry will tell you exactly what you wan to know and does not require credentials.

Here is the MS info on this command: https://www.microsoft.com/en-us/download/details.aspx?id=17148

\(ツ)_/

This is what you want. It will let you check to see that a port is open and responding, such RDP 3389. Powershell doesn't have a way to test an actual RDP connection that I'm aware of. If you have credentials and the server isn't too firewalled from where you'll be testing, you could try opening a remote powershell session. 


Monday, March 27, 2017 9:24 PM

The results of a successful PortQry to a different domain:

D:\scripts> D:\Tools\PortQryV2\PortQry.exe -e 3389 -p tcp -n w8test

Querying target system called:

 w8test

Attempting to resolve name to IP address...


Name resolved to 10.0.0.19

querying...

TCP port 3389 (ms-wbt-server service): LISTENING
D:\scripts> $LASTEXITCODE
0
D:\scripts>

Failed to find running RDS:

D:\scripts> D:\Tools\PortQryV2\PortQry.exe -e 3389 -p tcp -n 10.0.0.235

Querying target system called:

 10.0.0.235

Attempting to resolve IP address to a name...

Failed to resolve IP address to name

querying...

TCP port 3389 (ms-wbt-server service): NOT LISTENING
D:\scripts> $LASTEXITCODE
1
D:\scripts>

Notice that $LASTEXITCODE reflects the results.

\(ツ)_/


Tuesday, March 28, 2017 8:20 AM

Thank you for your answer.

Ping works fine but does not fit my need: ping is successfull before the target server completes the startup procedure: I need to ensure that a user can logon to the target server, while ping is successfull far before such condition occurs...

Many thabnks, anyway.

Mario


Tuesday, March 28, 2017 8:23 AM

PortQry is not ping and will only return true if RDS is running and ready for connections.

\(ツ)_/