The `Test-Connection` command is a PowerShell cmdlet that sends Internet Control Message Protocol (ICMP) echo request packets, or “pings”, to one or more computers. The cmdlet then returns the echo response replies.
`Test-Connection` is essentially the PowerShell version of the `ping` command that’s been used in Command Prompt for many years. However, `Test-Connection` is more powerful and flexible than `ping`.
Here is a basic example of `Test-Connection`:
Test-Connection -ComputerName www.google.com
This command sends ICMP echo request packets to www.google.com and then displays the echo response replies. By default, `Test-Connection` sends four “pings“, but you can change this with the `-Count` parameter.
If you want a simple true/false response indicating whether the host is reachable, you can use the `-Quiet` parameter:
Test-Connection -ComputerName www.google.com -Count 2 -Quiet
In this example, `Test-Connection` sends two pings to www.google.com and then returns `True` if any pings are successful and `False` otherwise.
`Test-Connection` is more flexible than `ping`, allowing you to perform tasks like sending a specific number of pings, sending pings to multiple computers, or even tracing the network route to a computer and displaying the latency and packet loss at each hop.
TEST AD SERVERS
Yes, you can use the `Test-Connection` cmdlet in PowerShell to check the availability of a Domain Controller. This cmdlet sends ICMP echo request packets (“pings“) to a specific computer and returns a Boolean value that indicates whether the computer responded.
Here’s an example where you replace ‘DCName‘ with the name of your Domain Controller:
Test-Connection -ComputerName DCName -Count 2 -Quiet
This command will ping the Domain Controller 2 times and return `True` if the Domain Controller is available and `False` otherwise. The `-Quiet` parameter tells PowerShell to return only a Boolean value, not the full ping response data.
If you want to test all Domain Controllers, you could use `Get-ADDomainController` to get a list of all Domain Controllers, and then use `Test-Connection` on each one, like this:
Get-ADDomainController -Filter * | ForEach-Object { Test-Connection -ComputerName $_.HostName -Count 2 -Quiet }
This will return `True` or `False` for each Domain Controller in your domain.
These commands should be run from an elevated PowerShell prompt and you may need the appropriate permissions to retrieve this information. Also, these cmdlets need the Active Directory module for PowerShell, which is typically installed on Domain Controllers or on machines where the Remote Server Administration Tools (RSAT) are installed. If you don’t have the module installed, you might need to install it first.