title: Run Command as administrator in PowerShell script. UAC
body: <p>OK here is my issue: </p>
  
  <p>I am trying to run a script remotely on a server. </p>
  
  <p>I am an administrator on both boxes, firewall exceptions are in place, remote admin is enabled, and everything else looks good that i can see. </p>
  
  <pre><code>invoke-command -ComputerName $ComputerName -ScriptBlock `
  {
      cd C:\Windows\System32\inetsrv\; 
      ./appcmd.exe ADD vdir /app.name:&lt;SiteName&gt;/ /path:/&lt;VDir Name&gt; /physicalPath:&lt;Path to files&gt;
  }
  </code></pre>
  
  <p>I keep getting the following error in return</p>
  
  <pre><code>ERROR ( hresult:80070005, message:Failed to commit configuration changes. Access is denied.
  </code></pre>
  
  <p>The server it is trying to run on is a server 2k8 R2 box and I am thinking the issue is a UAC problem. Is there anyway to get this to run as administrator without having to click yes on a UAC box? </p>
  
  <p>This piece of code will eventually become a script that will have to be completely automated. </p>
  
  <p>Any help would be greatly appreciated.</p>