Forum Discussion

Dave11's avatar
Dave11
Copper Contributor
Jun 17, 2020

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

Resources