title: Running a powershell script from a application pool user elevated priv
body: <p>I have a specific scenario that's troubling me was hoping for some insight from the community.</p>
  <p>I'm trying to run an add HTTPS binding &amp; link to certificate PowerShell script via a web-application that is running on it's own application pool identity.</p>
  <p>The PowerShell script requires elevated privilege's so it fails to run successfully and only gets to the bindings part but not the linking of the SSL certificate.</p>
  <p>I cannot call to run a saved script file with my code because the bindings are dynamically generated on the fly and require the web-application to replace the token that holds the binding.</p>
  <p>How can I successfully run the script below if it's ran via the web-application that is currently running it's application pool identity user? I've tried encompassing my script with an elevation tag but that fires a new elevated separate PowerShell window that doesn't work for me as this is all happening automatically without a user.</p>
  <pre><code>New-WebBinding -name &quot;example.domain&quot; -IPAddress &quot;XXX.XXX.XXX.XXX&quot; -Protocol https -HostHeader [DynamicallyLoadedViaWebApplication] -Port 443 -SslFlags 1
  $siteName = 'example.domain'
  $Cert = (get-item cert:&quot;\LocalMachine\WebHosting\THUMBPRINTHERE&quot;)
  $binding = Get-WebBinding -Name $siteName -Protocol &quot;https&quot;
  $binding.AddSslCertificate($Cert.GetCertHashString(), &quot;WebHosting&quot;)
  </code></pre>
  <p>I've tried shutting UAC off via the registry but that didn't help. The script above must be ran via the web-application with high enough privilege's to complete successfully</p>
  <hr />
  <p>UPDATE:</p>
  <p>Being that the 1st script to fire is done so via the <code>application pool identity</code> and not an administrator account is this method viable? I can eventually try switching the <code>application pool user</code> to an administrator but I'd like to avoid that if possible. Or any other ideas on how to do the binding via the <code>application pool</code> user?</p>