title: Can I RDP through mstsc and run a script on that remote desktop?
body: <p>I'm writing a script which needs to RDP to a few servers, do processes there and then come back.</p>
  
  <p><code>mstsc /v:&lt;computer&gt;</code> by itself looks great as it's security/credential prompt is the same as if you manually executed it.</p>
  
  <p>However, after some research it appears that's meant to be a command line utility and nothing more because trying things like: </p>
  
  <pre><code>mstsc /v:104.209.198.181 | Invoke-Command -ScriptBlock {"New-Item C:\Users\&lt;me&gt;\Desktop\Success.txt -ItemType file"} 
  </code></pre>
  
  <p>doesn't work.</p>
  
  <p>So I tried <code>Enter-PSSession &lt;computer&gt; -Credential $env:UserName</code> which people use but it looks like a mess to deal with compared to <code>mstsc</code> because it looks primitive (an article I read yesterday tried to say this type of prompt is ALWAYS a phishing scam which obviously it's not but try telling management), it doesn't auto-populate domains, and I get a WinRM error which I'm sure will be a rabbit hole.</p>
  
  <p>So is it possible to RDP with <code>mstsc</code> and then pipe commands to it so they're executed on that computer?</p>