Invoke-command error! What am I missing?

This topic contains 3 replies, has 2 voices, and was last updated by  Cody Everingham 2 years, 5 months ago.

  • Author
  • #34421

    Cody Everingham

    Here's the code:

    Invoke-Command -ComputerName -Credential 'mydomain\UserName' -ScriptBlock {
    $domain = "mydomain"
    $user = "domainuser"
    $password = Read-Host -Prompt "Enter password for $user" -AsSecureString
    $username = "$domain\$user"
    $credential = New-Object System.Management.Automation.PSCredential($username,$password)
    Add-Computer -DomainName $domain -Credential $credential

    Here's the error:
    [] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Default
    authentication may be used with an IP address under the following conditions: the transport is HTTPS or the destination is in the TrustedHosts
    list, and explicit credentials are provided. Use winrm.cmd to configure TrustedHosts.

    More info:

    It is Pingable
    It does have WinRM installed

  • #34422

    Tim Pringle

    Hi Cody,

    If you are referring to a computer by its IP address instead of its hostname, it is treated differently. You will need to set TrustedHosts to include the IP address. You can change this by doing the following on your own system.

    Set-Item -Path WSMAN:\localhost\Client\TrustedHosts -Value -Force
  • #34427

    Cody Everingham


    Very helpful, I got it to work! However, right now I would have to go back and change the script every time I would want to target another computer. when I use:

    $targetIP =
    Set-Item -Path WSMAN:\localhost\Client\TrustedHosts -Value $targetIP -Force

    I get the issue:
    Set-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by the parameter. Specified method is not supported.
    At line:4 char:1
    + Set-Item -Path WSMAN:\localhost\Client\TrustedHosts -Value $targetIP -Force
    + CategoryInfo : NotSpecified: (:) [Set-Item], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand

  • #34428

    Cody Everingham


    Never-mind, this was my bad. I needed to put that IP address in as a string.

    Thanks for the help!

You must be logged in to reply to this topic.