Which is best method to authenticate the Remote machine

Copper Contributor

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 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)

1 Reply

Hello Dave11,

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.