Powershell script to test login with admin credentials on multiple windows VMs

HK 21 Reputation points
2023-01-09T03:27:27.347+00:00

Hi All,

Can somebody please help me with the Powershell script for the below requirement. Need to check if our admin accounts have access to log into multiple windows servers without taking remote sessions of each VMs

  1. To test the RDP connectivity for multiple VMs at once
  2. Test admin user login without prompting for user name & password
  3. Script should give output in csv format for each server login result as "Success or Failed"

Thanks
HK

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,746 Reputation points
    2023-01-10T09:34:13.72+00:00

    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–

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.