Author Posts

January 1, 2012 at 12:00 am

by rcjay272 at 2013-02-17 15:44:26

I wrote a quick script to query a list of servers to check for active sessions on some terminal servers, but the output is ugly with no line separation between each server.

Is there a way in my script I could echo a line separator between each server output? See below for an example.....

Thank you for your help.

If there is a better way to get the same output I would be curious to see what is out there.

Rob

SCRIPT – – – –

$servers = Get-Content -Path C:\Load_Stuff\MonitoringScripts\TS_list.txt
ForEach ($server in $servers) {Get-TSSession -ComputerName $server -state ACTIVE }

OUTPUT – UGLY – – – –
PS C:\Load_Stuff\MonitoringScripts\PowerShell> .\GetActiveSessionList.ps1

Server SessionID State IPAddress ClientName WindowStationName UserName
—— ——— —– ——— ———- —————– ——–
ts01.LOAD.LOCAL 3 Active 10.4.13.149 AT2RIGHT-0015 RDP-Tcp#7 LOAD\User3.2.4_0015
ts01.LOAD.LOCAL 4 Active 10.4.13.187 AT2RIGHT-0025 RDP-Tcp#23 LOAD\User3.2.4_0025
ts02.LOAD.LOCAL 6 Active 10.4.13.177 AT2RIGHT-0038 RDP-Tcp#9 LOAD\User3.2.4_0038
ts02.LOAD.LOCAL 7 Active 10.4.13.209 AT2RIGHT-0049 RDP-Tcp#6 LOAD\User3.2.4_0049

I would like to see something like this to make it easier to read.....

PS C:\Load_Stuff\MonitoringScripts\PowerShell> .\GetActiveSessionList.ps1

Server SessionID State IPAddress ClientName WindowStationName UserName
—— ——— —– ——— ———- —————– ——–
ts01.LOAD.LOCAL 3 Active 10.4.13.149 AT2RIGHT-0015 RDP-Tcp#7 LOAD\User3.2.4_0015
ts01.LOAD.LOCAL 4 Active 10.4.13.187 AT2RIGHT-0025 RDP-Tcp#23 LOAD\User3.2.4_0025

******************************************************************************************************************

ts02.LOAD.LOCAL 6 Active 10.4.13.177 AT2RIGHT-0038 RDP-Tcp#9 LOAD\User3.2.4_0038
ts02.LOAD.LOCAL 7 Active 10.4.13.209 AT2RIGHT-0049 RDP-Tcp#6 LOAD\User3.2.4_0049

by mjolinor at 2013-02-17 16:37:40

Something like this?

$servers = Get-Content -Path C:\Load_Stuff\MonitoringScripts\TS_list.txt
ForEach ($server in $servers) {
Get-TSSession -ComputerName $server -state ACTIVE
"`n{0}`n" -f ('*'*80)
}

by rcjay272 at 2013-02-17 17:25:23

That is great.

Thanks for the help,

ROb