Hello there,
To check if a user can log in to multiple Windows servers without taking a remote session on each VM, you can use the Test-NetConnection cmdlet in PowerShell. This cmdlet allows you to test connectivity to a remote computer by sending an Internet Control Message Protocol (ICMP) echo request, or a TCP SYN packet to a target system. If the target system responds to the request, it is considered reachable.
Here is an example of a script that checks the RDP connectivity for multiple VMs at once and outputs the results in a CSV format:
Define an array of server names
$servers = @("server1", "server2", "server3")
Define the username and password to use for the connection test
$username = "admin" $password = ConvertTo-SecureString "password" -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential($username, $password)
Initialize an empty array to store the results
$results = @()
Loop through each server in the array
foreach ($server in $servers) {
Try to establish an RDP connection to the server
try { $session = New-RDPSession -ComputerName $server -Credential $credential # If the connection is successful, add a "Success" result to the results array $results += New-Object PSObject -Property @{ Server = $server Result = "Success" } # Disconnect the RDP session Remove-RDPSession -Session $session } catch { # If the connection fails, add a "Failed" result to the results array $results += New-Object PSObject -Property @{ Server = $server Result = "Failed" } } }
Export the results to a CSV file
$results | Export-Csv -Path "rdp_results.csv" -NoTypeInformation
This script defines an array of server names, and then loops through each server, attempting to establish an RDP (Remote Desktop Protocol) connection using the specified username and password. If the connection is successful, it adds a "Success" result to the results array. If the connection fails, it adds a "Failed" result to the results array. Finally, it exports the results to a CSV file.
--If the reply is helpful, please Upvote and Accept it as an answer–