title: Get a process's owners, send them messagebox and then kill the processes
body: <p>I trying to get a list of users, who are running an application, for instance chrome.exe. Then send them a message and set the countdown timer for 300 seconds and after this I need to stop these processes. I have tried the following <code>PowerShell</code>.</p>
  
  <pre><code>$owners = @{} 
  gwmi win32_process | % {
      $owners[$_.handle] = $_.getowner().user
  }
  get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
  </code></pre>
  
  <hr>
  
  <h2>Answer was closed. below you can see a solution:</h2>
  
  <pre><code>$USERLIST = (Get-WmiObject -Class Win32_Process -Filter "Name='tsappldr.exe'" -ComputerName "SRUS270137C").getowner().user
  ForEach ($computer in $USERLIST) {
  $CmdMessage = {C:\windows\system32\msg.exe   $computer  /v 'Cancel your session'} $CmdMessage | Invoke-Expression 
  }
  Start-Sleep -m 5  #time-out for 5 minutes
  
  get-process tsappldr, tpedrte  | stop-process -force
  </code></pre>