edm365f31
 Basic Member Posts:100

 |
| 19 May 2009 07:32 AM |
|
Is there anybody that can provide me or point me to this type of script. I am working on a script that will log-off ICA Citrizx sesions but was told that I also need to be able to log-off rdp sessions. This script have not been tested yet, but if there's anything that will improve, much appreciate it.
function LogOffSession{ Param([string]$server) $server = $Server.ToUpper() $mfsrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer $mfsrv.initialize(6,"$server") $sesscount = $mfsrv.sessions.count $sessions = $mfsrv.sessions
$count = 0 $i = 0 $sessions | ForEach-Object{ $i++
### Make sure I log off the $username only once if he’s logged on multiple times if ($_.username) { $count++ if ($count -eq 1) { $_.logoff(0) Write-Host “Logging off: $_username from $server” $count++ } } } } }
|
|
|
|
|
Brandon Shell [MVP]
 Basic Member Posts:396

 |
| 19 May 2009 07:56 AM |
|
Why would you want to randomly log people off? I assume you don't which means we are missing a critical piece of the puzzle. Can you elaborate on exactly what your goal is? |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
edm365f31
 Basic Member Posts:100

 |
| 19 May 2009 08:10 AM |
|
In our environment at the end of the day we need to log off all session, what ever their state are, but I need to log them off properly, enumerate the session user and maybe the state of the session I am logging off in the output. ON the weekend the log session script need to be a function followed by reboot script script/function. We use a Tidal Enterprise Scheduler to run script against our boxes. I also need to log-ff Rdp sessions at the same time if it exist. thanks for your help |
|
|
|
|
edm365f31
 Basic Member Posts:100

 |
| 20 May 2009 10:38 AM |
|
Brandon This one works right now not really clean but it does disconnects RDP and ICA, I notice that there is always an extra 3 sessions maybe a virtually or automatically opened. I only need to clean the write -host for maybe specific sessionstate, if there's anything else you can suggest, I would appreciate it. Thanks Edm
Param( [string]$server = $(throw "Syntax:./LogOffCitrixSession.ps1 -server- ") # Note: - is the greater and less than sign ) $server = ($Server).ToUpper() $mfsrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer $mfsrv.initialize(6,"$server") $sesscount = $mfsrv.sessions.count $sessions = $mfsrv.sessions
Write-Host "Farm: " $mfsrv.farmname Write-Host "Total: " $sesscount Connections
$count = 0 $i = 0 $sessions | ForEach-Object{ $i++
if ($_.username) { $_.logoff(0) Write-Host "Logging off:" USER: $_.username" "SessionName: $_.Sessionname" "Running: $_.AppName" "from $server
} } |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Advanced Member Posts:565

 |
|
edm365f31
 Basic Member Posts:100

 |
| 20 May 2009 12:58 PM |
|
Noted thanks |
|
|
|
|