title: IPC Port Access Denied
body: <p>I'm trying to execute <code>mstest</code> remotely via <code>Invoke-Command</code> in PowerShell.  The PowerShell command within the scriptblock is a basic <code>mstest</code> call with a single test container and a specified results file.  It works correctly if run from within RDP on the remote server.</p>
  
  <p>However, if I run it remotely via <code>Invoke-Command</code>, <code>mstest</code> returns an exception</p>
  
  <blockquote>
    <p>Failed to queue test run 'Administrator@AEPRFDLY00ALL00 2016-01-06 10:22:40': Unable to start the agent process.</p>
  </blockquote>
  
  <p>Looking at event viewer on the remote machine, I see a series of exceptions, starting with:</p>
  
  <pre>(QTAgent32_40.exe, PID 2432, Thread 1) AgentProcess: Failed to get agent process proxy: System.Runtime.Remoting.RemotingException: Failed to connect to an IPC Port: Access is denied.
  Server stack trace: 
    at System.Runtime.Remoting.Channels.Ipc.IpcPort.Connect(String portName,             Boolean secure, TokenImpersonationLevel impersonationLevel, Int32 timeout)
    at System.Runtime.Remoting.Channels.Ipc.ConnectionCache.GetConnection(String portName, Boolean secure, TokenImpersonationLevel level, Int32 timeout)
    at System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
    at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
  Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at Microsoft.VisualStudio.TestTools.Agent.IAgentProcessManagerAccessManager.GetAgentProcessProxy(String executionKey)
    at Microsoft.VisualStudio.TestTools.Agent.AgentProcess.GetAgentProcessProxy()</pre>
  
  <p>I am executing the command using <code>Invoke-Command</code> using the same credentials used for RDP (in which session the command is successful).  Also, in the <code>Invoke-Command</code> scriptblock, if I call <code>whoami /priv</code>, I see a response with 23 privilege names.  Based on my previous research, this means I'm running in an elevated session.  <code>Invoke-Command</code> is using Authentication = Negotiate.</p>
  
  <p>I don't think that this is a firewall issue because I can run other commands from within the scriptblock successfully, just not <code>mstest</code>, so the PowerShell session is starting on the remote machine.</p>
  
  <p>Note that this is detailed in <a href="https://social.technet.microsoft.com/Forums/windows/en-US/4c09a282-2d3c-47db-b1bb-2c98a531226a/ps-remoting-failed-to-connect-to-an-ipc-port-access-is-denied?forum=winserverpowershell" rel="nofollow">this forum post</a> but without resolution.</p>