How can I issue mstsc in batch mode, no console se

2019-09-21 05:06发布

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条回答
干净又极端
2楼-- · 2019-09-21 05:21

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
}
查看更多
登录 后发表回答