title: Execute a batch script as admin from inside powershell
body: <p>I am trying to schedule a weekly task that takes a backup of some important data (Eventually, I want to run the PowerShell script from Windows task manager). The software provider already has a batch script for this (backup.bat). I have written a powershell script that invokes this batch script. But invoking backupdb from powershell fails throwing a "Permission denied" error message. </p>
  
  <p>I tried the below, which did not work:</p>
  
  <pre><code>start-process $BackupCmd -verb runas -ArgumentList "$Flags `"$BackupFile`""
  </code></pre>
  
  <p>After looking at several posts on SO and other forums, I was able to find answers for running a powershell script from inside a batch script as admin and not the other way round.</p>
  
  <p><a href="http://social.technet.microsoft.com/Forums/windowsserver/en-US/acf70a31-ceb4-4ea5-bac1-be2b25eb5560/how-to-run-as-admin-powershellps1-file-calling-in-batch-file" rel="nofollow noreferrer">how to run as admin powershell.ps1 file calling in batch file</a>, <a href="https://stackoverflow.com/questions/20900755/run-a-powershell-script-in-batch-file-as-administrator">Run a powershell script in batch file as administrator</a> and <a href="https://stackoverflow.com/questions/19335004/how-to-run-a-powershell-script-from-a-batch-file">How to run a PowerShell script from a batch file</a></p>
  
  <p>EDIT 1:</p>
  
  <p>1.I run the batch script and the PowerShell script as the same user. </p>
  
  <p>2.I tried elevating the PowerShell using "-verb runas", but did not work. Running the PowerShell script from the same elevated window as the batch script does not work.</p>
  
  <p>3.Pasting the PowerShell script below:</p>
  
  <pre><code>$CurrentDate = get-date -format yyyyMMdd
  $BackupStartDate = (get-date).AddDays(-7).ToString("yyyyMMdd") 
  $BackupDir = "&lt;directory path&gt;"
  $BackupFile = $BackupDir + "Backup-" + $BackupStartDate + "-to-" + $CurrentDate + ".txt"
  $BackupCmd = "C:\Progra~1\bin\backup"
  $Verbose = " -v "
  $ArchiveStart = " -S " + $BackupStartDate
  $Flags = $Verbose + $ArchiveStart
  
  # Both commands below do not work
  start-process $BackupCmd -verb runas -ArgumentList "$Flags `"$BackupFile`""
  &amp; $BackupCmd $Flags `"$BackupFile`"
  </code></pre>
  
  <p>4.Error:</p>
  
  <pre><code>backup.bat : Error writing to the debug log! &lt;type 'exceptions.IOError'&gt; [Errno  13] 
  Permission denied: 'C:\\Program Files\\tmp\\debug.log'
  (2014/06/05 12:42:01.07) [8764] --&gt; Exception encountered.  &lt;Unable to load config file!&gt;
  Error writing to the debug log! &lt;type 'exceptions.IOError'&gt; [Errno 13] Permission denied:
  </code></pre>
  
  <p>Thanks.</p>