Which is best method to authenticate the Remote machine

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
if(-not($Session)){
Remove-PSSession $Session
throw "Access Denied. Invalid credentials."
}
Remove-PSSession $Session
Can any one suggest any better approach to authenticate the remote machine with credentials. Above cases has a loop-hole that it will freeze when connection is lost(no error comes up just hangs)

Hello Dave1185,
What is your scenario?
Are you trying to accomplish 1 to 1 remoting or 1 to many?

I would strongly suggest to read Secrets of PowerShell Remoting. It will answer most of your remoting questions and explain best practices.

Hope that helps.

Dave,
when you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

https://social.technet.microsoft.com/Forums/en-US/bc1749b3-3325-48b4-a1f9-16dcd71f6bc5/which-is-best-method-to-authenticate-the-remote-machine?forum=winserverpowershell

Thanks

[quote quote=236389]Hello Dave1185,

What is your scenario?

Are you trying to accomplish 1 to 1 remoting or 1 to many?

I would strongly suggest to read Secrets of PowerShell Remoting. It will answer most of your remoting questions and explain best practices.

Hope that helps.

[/quote]
Hey, Thanks for your reply and apologies for reposting on other platforms Olaf.
My scenario is 1 to 1 remoting. Can u help me more on this,

Thanks in advance

Hi AndySvints,
My scenario is 1 to 1 remoting. And I have read the book suggested by you. I need to say it cleared many concepts. But still, I cannot accomplish

  • to identify if the remote machine is reachable or not.
  • if there is connection failure during the execution of scripts the output of PowerShell goes in an infinite loop.