title: Is there a way to switch user in powershell to run a command without password prompt?
body: <p>I want to log off a user on a remote machine using the powershell code:</p>
  
  <pre><code>$session = ((quser /server:$system | Where-Object { $_ -match $user }) -split ' +')[2]
  logoff $session /server:$system
  </code></pre>
  
  <p>Currently these commands are executed by account : NT AUTHORITY\SYSTEM but i want to execute the commands using another user.</p>
  
  <p>I have tried using :</p>
  
  <pre><code>runas /user:administrator /savecred "quser /SERVER:$server"
  </code></pre>
  
  <p>but it prompts for password, I want to execute the script automatically . Is there any way I can switch the user without having to pass the password through terminal?</p>