Powershell to Get List of all RDP Sessions for Each Server Defined in a CSV

Rich Ellis 1 Reputation point
2021-11-08T17:54:46.687+00:00

Hello,

I have admin on every server. I would like to create a PowerShell script to get all RDP sessions currently logged into every server we have, with logon time. I have the server names in a CSV but not sure how I would build the script. I can use quser on a 1 by 1 basis but not sure how this could be done in a PowerShell script. PowerShell newbie here.

Any ideas? TIA

Windows for business Windows Client for IT Pros User experience Remote desktop services and terminal services
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-11-08T18:42:51.957+00:00

    Hi @Rich Ellis ,

    maybe this is an option: https://www.powershellcenter.com/2021/07/04/powershell-module-to-get-rdp-session-info/

    After installing the module the script could look like this (not tested by myself):

    $serverlist = "Server1", "Server2", "Server3"  
    $serverlist | ForEach-Object {  
        Write-Host "Proceeding $_"  
        Get-PSCActiveSession -Name "$_" | Export-Csv c:\junk\RDPsessions.csv -NoTypeInformation  
    }  
    

    Getting the content of your CSV file depends on the format.
    One option could be Import-CSV: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.2
    Or Get-Content: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. Rich Matheisen 47,901 Reputation points
    2021-11-08T19:07:17.74+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.