I'm trying to establish a connection to a remote server that is not on Domain environment. When running the Set-Item alone on PowerShell console without the script it works for some reason on the script it doesn't.
$passwd = convertto-securestring -String <Password> -AsPlainText -Force
$cred = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList "developer", $passwd
$server = Read-Host -Prompt 'Input your server IP'
Set-Item wsman:\localhost\client\TrustedHosts -Value $server -Force
$session = new-pssession -computername $server -credential $cred
When I run the above code, I receive the message
Set-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by the parameter. Specified method is not supported.