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)
I don't think that cross posting will give different or more detailed result: https://powershell.org/forums/topic/which-is-best-method-to-authenticate-the-remote-machine/
My advice is still the same:
Read Secrets of PowerShell Remoting.
Hope that helps.