Get Logged-In User and Send Messages

This PowerShell script allows you to get the user currently logged into a computer using the system account.

Get-WmiObject Win32_Process -f 'Name="explorer.exe"'  |%  getowner  |% user

PowerShell script output example

Send Message to Logged-In User

$sessionId = (Get-WmiObject Win32_Process -Filter 'Name="explorer.exe"').SessionId | Select-Object -Unique
msg.exe $sessionId "$message"

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.