How can I issue mstsc in batch mode, no console session?

纵然是瞬间 提交于 2020-01-07 08:28:24

问题


I need to issue mstsc and get a status back that this command works for a series of IPs. No RDP console.

I cannot use WMI ports, just RDP 3389 to the device. Would love to use PowerShell remote commands but I read they use WMIObjects which implies using WMI ports.

I used psexec and it uses WMI ports. This worked in my lab but when I hit the real firewalls, blocked.

I've tried several methods, each hits the WMI ports or causes the RDP console to pop on the from server. I also need the event to report back connected or not found into a file for further decision making.


回答1:


Terminal Services were made for interactive use, not batch mode. If you want to check if a port is accessible in PowerShell you can try to establish a TCP connection to it:

$servers = ...

foreach ($server in $servers) {
  $clnt = New-Object Net.Sockets.TcpClient
  try {
    $clnt.Connect($server, 3389)
    "$server:`tOK"
  } catch {
    "$server:`tnot available"
  } finally {
    $clnt.Dispose()
  }
}

On more recent Windows versions there's also Test-NetConnection:

$servers = ...

foreach ($server in $servers) {
  Test-NetConnection -Computer $server -Port 3389
}


来源:https://stackoverflow.com/questions/35138873/how-can-i-issue-mstsc-in-batch-mode-no-console-session

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!