Logoff disconnected sessions at Citrix XenApp farm

14 ביולי 2008

תגיות: ,
אין תגובות

או למעשה, די נמאס לי מכל אלה שבממתינה, למאזין הבא.

סקריפט קטן, אשר מבוסס בעיקרו על סקריפט של Citrix הנותן מידע על sessions בחווה.
הטריק היחיד כאן הוא לדעת איך מצבי session שונים מוצגים בחווה:
0 – unknown
1 – active
2 – connected
3 – connecting
4 – shadowing
5 – disconnected
6 – idle
7 – listening
8 – resetting
9 – down

ואחרי שהטריק ידוע, הנה הסקריפט המלא:

<package>
    <job id="Sessions">

        <comment>

        File:           logoff_dis_sessions.wsf
        Description:    Logoff disconnected sessions.
        Requirements:   WSH 5.5 or higher.
        Author:        Gadi Feldman (based on Citrix template).
        Version:    1.1
        Date:    13/7/08
        </comment>
        <runtime>
            <description>
                Logoff disconnected sessions.
            </description>
            <example>
                CScript //nologo logoff_dis_sessions.wsf
            </example>
        </runtime>
        <reference object="MetaFrameCOM.MetaFrameFarm"/>
        <script language="VBScript">
            Dim theFarm, aSession, SessionState

            '
            ' Create MetaFrameFarm object
            '

            Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
            if Err.Number <> 0 Then
                WScript.Echo "Can't create MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            '
            ' Initialize the farm object.
            '

            theFarm.Initialize(MetaFrameWinFarmObject)
            if Err.Number <> 0 Then
                WScript.Echo "Can't  Initialize MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            '
            ' Are you Citrix Administrator?
            '

            if theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
                WScript.Echo "You must be a Citrix admin to run this script"
                WScript.Echo ""
                WScript.Quit 0
            End If

            '
            ' Print out the farm name.
            '

            'WScript.Echo "MetaFrame Farm Name: " & theFarm.FarmName
            'WScript.Echo ""

            '
            ' Display all sessions in the farm.
            '

            'WScript.Echo "All sessions in the farm (" & Now & ")"
            'WScript.Echo "————————————————"

            For Each aSession In theFarm.Sessions

                if Err.Number <> 0 Then
                    WScript.Echo "Can't enumerate sessions"
                    WScript.Echo "(" & Err.Number & ") " & Err.Description
                    WScript.Echo ""
                    WScript.Quit Err.Number
                End if

                        ' To logoff sessions from specific servers
                        'if aSession.ServerName = "VMSERVER04" or aSession.ServerName = "VMSERVER01" Then
                                    if aSession.SessionState = 5 then
                                                aSession.logoff(2)
                                    End if
                        'End if
            Next
        </script>
    </job>
</package>

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *