none
How do I use Invoke-Command correctly?

    Question

  • Im trying to run the command test-outlookconnectivity -protocol:tcp or http -trustanysslcert:$true.  I'm wanting to run it on a remote machine as if I were
    on the machine, and have the output returned to the screen of the local machine.

    As stated in this article: http://technet.microsoft.com/en-us/library/dd347578.aspx,
    i tried to use the invoke-command.  My syntax looks like this:

    Invoke-command -comuptername <sever name> -scriptblock {test-outlookconnectivity ....} -authentication Kerberos.  However I got this error:

    "Connecting to remote server failed with the following error message : WinRM
    cannot process the request. The following error occured while using Kerberos
    authentication: The network path was not found."

    Anyone got any idea what im doing wrong?  I have permissions to run the cmd
    on both machines and I can also successfully ping the remote machine.?? 

    Thanks.


    JCtech1123, Cheers

    Thursday, March 08, 2012 12:21 AM

Answers

  • So I was able to use a $variable for the -connectionuri.  I used this:

    $server = "http://" +  $servername + "." + $domainid + "/powershell", then

    -connectionuri $server.  I am able to put that into a foreach loop with serveral other commands.


    JCtech1123, Cheers

    • Marked as answer by JCtech1123 Tuesday, March 27, 2012 8:43 PM
    Tuesday, March 27, 2012 8:43 PM

All replies

  • Using invoke-command on a remote host requires that the target machine have WinRM installed and configured to accept your connection and provide you with a remote runspace.

     

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa384372(v=vs.85).aspx


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, March 08, 2012 12:59 AM
  • OK so I got the invoke-command to work.  What I did was use a variable called $session.  The session was the following:

    $session = new-pssession -configurationname microsoft.exchange -connectionuri http://servername.fqdn/powershell -authentication kerberos

    invoke-command -session $session -scriptblock {test-outlookconnectivity -protocol:tcp}.  That allowed the command to run remotely.

    Here is what im wanting to be able to to though.  I want to be able to specify a $variable in the -connectionuri, instead of http://specific server name, I have a list of server names to run a pssession to each, and I want to be able to create one to each server.  Is there a way to do something like:

    $variable = servers names, and -connectionuri $variable?

    Cheers.


    JCtech1123, Cheers

    Sunday, March 11, 2012 11:15 PM
  • So I was able to use a $variable for the -connectionuri.  I used this:

    $server = "http://" +  $servername + "." + $domainid + "/powershell", then

    -connectionuri $server.  I am able to put that into a foreach loop with serveral other commands.


    JCtech1123, Cheers

    • Marked as answer by JCtech1123 Tuesday, March 27, 2012 8:43 PM
    Tuesday, March 27, 2012 8:43 PM