Invoke-command error! What am I missing?

Welcome Forums General PowerShell Q&A Invoke-command error! What am I missing?

This topic contains 3 replies, has 2 voices, and was last updated by

2 years, 11 months ago.

  • Author
  • #34421

    Points: 0
    Rank: Member

    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

    Points: 60
    Rank: Member

    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

    Points: 0
    Rank: Member


    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

    Points: 0
    Rank: Member


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

    Thanks for the help!

The topic ‘Invoke-command error! What am I missing?’ is closed to new replies.