title: How to supply Admin credentials in Powershell script
body: <p>I have have created a logon script which will remove users from the local administrators group on each computer. The entire process must run completely silently. The Powershell script must run as Administrator and I have the following code which self-elevates my script:</p>
  
  <pre><code># Self-elevate the script (Run as Administrator)
  if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
   if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
    $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments 
    Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine -WindowStyle Hidden
   }
  }
  </code></pre>
  
  <p>The only issue is that for end-users, when they logon, the self-elevation requires an Admin username and password. I need to supply Admin credentials automatically to keep this entire process running completely silently. How can I provide admin credentials?? See image link:
  <a href="https://i.stack.imgur.com/HpmbD.png" rel="nofollow noreferrer">https://i.stack.imgur.com/HpmbD.png</a></p>
  
  <p>Thank you!</p>