As of now I tried using Wsman commands and it succeed in most cases.
Here is the sample code for that:
$Password = ConvertTo-SecureString $password -AsPlainText -Force
$Username = $username
$Cred = New-Object System.Management.Automation.PSCredential ($Username, $Password)
$Session = New-PSSession -ComputerName $Target.ip -Credential $Cred
throw "Access Denied. Invalid credentials."
Can anyone suggest any better approach to authenticate the remote machine with credentials Above cases has a loop-hole that it will freeze when the connection is lost(no error comes up just hangs)