Powershell – Quickly check if current user has access on target server

powershell

Whenever I use Get-Service with a user that does not have access on the target server it takes a large amount of time to timeout.
This is results in an increased amount of time necessary to run a script

Is there a way to find out if a user has access on the target sever? I want to use that kind of functionality in my script to decrease the amount of system resources necessary.

Any and all help is greatly appreciated.

Best Answer

Test-Connection (TechNet article here) sends ICMP packets to check for response across the network. It is a PowerShell 2.0 cmdlet.

So if you do:

Test-Connection -count 2 -quiet

it will send 2 ICMP packets and return $true if any are successful or $false if all are dropped.