Get list of user sessions using a particular remote app using powershell -
we're putting powershell script deploy new versions of applications onto our servers. need list of rdusersession
objects running our application.
we're finding get-rdusersession
command -collection option return users on system, including administrators logged in remotely, not running remoteapp.
what want kick off users running our remote applications can perform update.
right list of rdusersessions
, send them messaage using send-rdusermessage
, we're finding sending message, , booting off, admins trying run script.
is there way list of applications running in rdusersession
?
#load applications in array $arr = @("a.exe", "b.exe") #get rd user sessions $rdsessions = get-rdusersession #create blank array capture users $usrarr = @() #loop through applications in array foreach($app in $arr) { #loop through each of sessions. foreach($rdsession in $rdsessions) { #check application $proc = get-wmiobject -class win32_process -filter "name = $app" #compare rdsession applicaitons session. if($rdsession.id -eq $proc.sessionid) { #load true hash $obj = new-object -typename psobject -property @{user = $rdsession.username; application = $app} $usrarr += $obj } } } #now can take data in array , send message. foreach($usr in $usrarr) { #send email or net send message. #code here.... }
Comments
Post a Comment