2

I want to execute a .cmd file on a remote server, through Powershell. This works well:

Invoke-Command -ComputerName <computerName> -credential $cred -ScriptBlock {&"C:\...\Script.cmd"}

But what is the syntax to run Script.cmd "as administrator" ?

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
Sean
  • 923
  • 3
  • 14
  • 36
  • $cred has the credentials for the remote machine. Did you specify administrator in $cred? – Χpẘ Dec 08 '13 at 19:38
  • possible duplicate of [PowerShell: Running a command as Administrator](http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator) – Victor Zakharov Dec 09 '13 at 19:27

1 Answers1

0

Your script block should be:

-Scriptblock {Start-Process -Path "C:\...\Script.cmd" -Verb Runas}

Check out the Start-Process cmdlet and the verb runas, that will get you there. Optionally, include -wait with that cmdlet to wait for the cmd to finish before returning.

MDMoore313
  • 3,233
  • 1
  • 23
  • 38