title: Running batch file on Remote Computers using PowerShell 2.0
body: <p>I am trying to run a exe on remote machines which would basically uninstall a product agent. below is the code:</p>
  
  <pre><code>$test = Get-Content PC.txt
  
  foreach ($a in $test)
  {
     $curr = Get-Location
     Set-Location \\$a\Admin$\System32\CCMSetup
     .\ccmsetup.exe /uninstall
     Set-Location $curr
  }
  </code></pre>
  
  <p>It doesn't work. I ended up removing the program from the host computer itself :)</p>
  
  <p>Alternate Option: I created a batch file with the command line:</p>
  
  <pre><code>cd C:\Windows\System32\ccmsetup
  ccmsetup /uninstall
  exit
  </code></pre>
  
  <p>It seems the above can also be achieved using Invoke-Command. </p>
  
  <pre><code>Invoke-Command -ComputerName $client -FilePath UninstallCCM.cmd
  </code></pre>
  
  <p>Apparently, it does not accept batch file. I would like to keep it as simple as possible. </p>
  
  <p>Currently I am using PSExec for installing and uninstalling the program. Do I need to enable PS Remoting (WinRM) on every remote machine on whom I need to execute scripts using PowerShell?
  Can someone please help? Thanks in advance.</p>