question

RichEllis-4974 avatar image
0 Votes"
RichEllis-4974 asked RichMatheisen-8856 answered

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

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-server-powershellremote-desktop-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

Hi @RichEllis-4974 ,

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://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.2
Or Get-Content: https://docs.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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.