title: Script to Kill All RDP Sessions
body: <p>I am trying to create a simple script to kill ALL remote desktop sessions, active or disconnected, without rebooting the server. My server OS is Windows Server 2012R2 with Remote Desktop Services enabled and licensed.</p>
  <p>I found a simple batch file script here to do this task: <a href="https://community.spiceworks.com/topic/428637-log-off-all-terminal-server-session-server-2012" rel="nofollow noreferrer">enter link description here</a></p>
  <p>When I run this script locally on my terminal server, I get an error in the batch file runs that says: Session Disc not found</p>
  <p>And only the console user is logged off. Can anyone tell me what is wrong with this script?</p>
  <pre><code>query session &gt;session.txt
  for /f &quot;skip=1 tokens=3,&quot; %%i in (session.txt) DO logoff %%i
  del session.txt
  </code></pre>
  <p>My Session text file looks like this:</p>
  <pre><code> SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
   services                                    0  Disc                        
   &gt;console           Administrator            13  Active                      
                     wcunningham              18  Disc                        
                     kstarkey                 25  Disc                        
   rdp-tcp#11        cyannone                 52  Active                      
   rdp-tcp                                 65536  Listen                      
  </code></pre>