Friday, January 21, 2011

A trick in Powershell 2.0

How to comment-out multiple lines in Powershell ?

Block your PowerShell syntex within @" "@ symbol . Starting with @" and end with "@ . But mind one thing useing the symbol you can only comment out PowerShell syntex , no other arbitary lines.

@" "@ String known as “Here-Strings"

A powershell script which will report you the Loded Xenapp servers which are having more than 9000 load.

You can schedule the script on every one hour (as per your environment) useing Windows Scheduler.

"
Add-PSSnapin citrix.xenapp.commands
cls
$log_file="W:\MaxLoad.log"
Clear-Content $log_file

cls
$servers = Get-XAZone | Get-XAServer -OnlineOnly $test = Get-XAServerLoad $servers | where-object {$_.load -gt "9000"}
$a = @{Expression={$_.ServerName};Label="Server Name";width=15}, @{Expression={$_.Load};Label="Load";width=10}, @{Expression={$_.LoadEvaluatorName};Label="LOAD EVALUATOR NAME";width=40}


$test | Format-Table $a >> $log_file
if ($test -ne $null)
{
echo "Sending email"
$smtpServer = "SMTP Server Address"
$msg = new-object Net.Mail.MailMessage
$msg.isBodyhtml = $true
$msg.Priority = [System.Net.Mail.MailPriority]::High
$att = new-object Net.Mail.Attachment($log_file)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "From Address"
$msg.To.Add("To address")
$msg.Subject = "Server(s) Load Reached 9000"
$msg.Body = "List of server(s) that reached the load greater than 9000."
#$msg.Body = Get-Content $log_file
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
}
"

Thursday, January 20, 2011

Error: You did not authenticate correctly. Please try again or contact you system administrator... when opening the License Management Console

Symptoms:

When attempting to open the License Management Console (LMC) users receive the following error message:
“You did not authenticate correctly. Please try again or contact you system administrator.”


Resolution : 

Users attempted to log in to the LMC with the wrong credentials. Check the tomcat-users.xml file located in:  Program Files\Citrix\Licensing\LMC\Tomcat\conf  and make an entry of your user credentials.

Thursday, January 13, 2011

Disable ICA Load Evaluator

How to Take a XenApp Server Offline with Load Evaluator and Powershell 

Requirements: XenApp 4.5 or 5.0 with Hotfix Rollup Pack 06

Procedure : 

  •  In the XenApp Advanced Configuration console, right click the Load EvaluatorsNew Load Evaluator. node and select



  • Name your load evaluator and assign Scheduling as the only rule.




  • Remove all intervals from the scheduling rule. This prevents any server with this assigned rule from taking any connections.



    •  Once you have the offline Load evaluator created, you can use PowerShell ian a script or command line to take the server offline using the following PowerShell command:
      Set-XAServerLoadEvaluator [ServerNAme] [LoadEvaluatorName] 
    • To reset the server to the default load evaluator, use the following PowerShell command.
      Reset-XAServerLoadEvaluator [ServerName]

    Create the above Load Evaluator useing the below powershell script . Run the script useing ./Add-DisableICALogonLE.ps1 -name [Load_EvaluatorName]

    "
    # NAME
    #     Add-DisableICALogonLE.ps1
    #
    # SYNOPSIS
    #     Creates a Load Evaluator with an empty Schedule Rule.
    #
    # SYNTAX
    #     .\Add-DisableICALogonLE.ps1 -name Name [-description Description]
    #
    # DETAILED DESCRIPTION
    #     A Load Evaluator with an empty Schedule Rule will maximize a XenApp
    #     server's load. Thus, it won't accept new ICA sessions while active
    #     and disconnected sessions are not affected.
    #
    # AUTHOR
    #     Frank-Peter Schultze http://www.fpschultze.de/
    #
    # DATE
    #     27-Jul-2008

    Param(
      $name = $(throw "Load Evaluator name must be specified"),
      $description = "Takes server offline for maintenance purposes"
    )

    $MetaFrameWinFarmObject = 1
    $LMRuleSchedule = 5

    $myfarm = New-Object -ComObject "MetaFrameCOM.MetaFrameFarm"
    $myfarm.Initialize($MetaFrameWinFarmObject)
    $myfarm.LoadEvaluators | %{if ($_.LEName -eq $name) {
        Write-Warning "The load evaluator `"$name`" already exists."; break
      }
    }

    Write-Verbose "Creating Load Evaluator `"$name`" . . ."
    $newrule = New-Object -ComObject "MetaFrameCOM.MetaFrameLMRule"
    $newrule.RuleType = $LMRuleSchedule

    $allrules = New-Object -ComObject "MetaFrameCOM.MetaFrameLMRules"
    $allrules.AddRule($newrule)

    $newle = New-Object -ComObject "MetaFrameCOM.MetaFrameLoadEvaluator"
    $newle.LEName = $name
    $newle.Description = $description
    $newle.Rules = $allrules
    $newle.SaveData()

    "

    How to Determine which MetaFrame XP or Presentation Servers are Connected to a SQL Data Store

    How to Determine which MetaFrame XP or Presentation Servers are Connected to a SQL Data Store 

     

    This article describes how to determine which MetaFrame XP or Presentation servers are connected to a SQL data store.
    From the SQL server:
    1. Run the SQL Query analyzer.
    2. Type the following statement:
      Select * from master.dbo.sysprocesses where program_name='Citrix IMA'
      Note
      : Single quotes must be applied to “Citrix IMA”.
    3. Execute the statement by pressing F5 or the Execute button.
      The output displays all of the open connections from MetaFrame XP or Presentation servers to the SQL server.

     

    How to Find if a Hotfix Is Installed in a Farm By Directly Querying the SQL Data Store

    Summary 
    This article describes how to find out if a Hotfix is installed in a farm by querying directly the SQL datastore.

    Procedure:  

    • Log on to the SQL server and open SQL Server Management Studio.
    • Once authentication to the SQL server is complete, click New Query.
    • Change the Database selector to point to the database which stores the farm data store you wish to query. 
    • Copy the following SQL code in the newly recreated query window in the right hand panel of the SQL Server Management Studio console.  
    Select substring (cast (RDN as nvarchar), patIndex('%--%', cast(RDN as nvarchar))+2, 100) as 'Hotfix', substring (cast (RDN as nvarchar), 1, patIndex('%--%', cast(RDN as nvarchar))-1) as 'Server'
    from keytable where contextID = (Select nodeid from keytable where cast(rdn as nvarchar) = 'MFHotFixFolder')
    AND SubString(cast (RDN as nvarchar), patIndex('%--%', cast(RDN as nvarchar))+2, 100) = 'PSE400W2K3R01'


    If you wish to list all Hotfixes stored in the database, use the following query.

    Select distinct substring (cast (RDN as nvarchar), patIndex('%--%', cast(RDN as nvarchar))+2, 100) as [Hotfix] from keytable where contextID = (Select nodeid from keytable where cast(rdn as nvarchar) = 'MFHotFixFolder')



    Citrix Daily Server testing script useing Powershell 2.0 and MFCOM objects.

    N.B : The script is applied on CPS 4.0 onwards only

    Please note that before executeing the script make sure you have powershell 2.0 and Powershell SDK for Xenapp is installed on the server.


    Unable to save file in the local drive

    Unable to save file in the local C drive (local drives).

    How to resolve the Request or Problem
     
      Technical resolution
    • The issue occures due to a file security setting on the local machine. After loging into Citrix , just double click on Citrix connection Center icon which will usally appear in System Tray by the clock. Open it and click the 'File Security' button.  They probably have theirs set to Read Access instead of Full Access.


      • In case of Citrix Web client only . This can be done without loging into Citrix, by editing the webica.ini file located in <root directory>\Documents and Settings\<username>\Application Data\ICAClient folder . 
                           [Access]
                           GlobalSecurityAccess=405
                           405 = read/write
                           404 - read only.


    Internet Branding Policy delay

    Logons Hang at "Applying Internet Explorer Branding Policy" When Connecting to XenApp Servers with Internet Explorer 7

    Technical resolution
    • During login to Citrix published applications, the launch process “hangs” for 20 seconds on the Branding IE Policy. This delays the launch of the application.
      • It's a known issue of Microsoft Internet Explorer 7 and they have alredy released a hotfix(KB941158) for that . Click here for details.
      • The hotfix is only applicable for Citrix Standard build which means Windows 2003 Server SP2 Enterprise Edition with Citrix Presentation Server (XenApp) 4.5 Rollup 5 with Internet Explorer 7 .
      • They have different hotfix for Windows 2003 X64 or Servers running IE 8.
        Patch Installtion
    • Follow the below steps to install and enable the patch:
      • Obtain the patch from here and install it on the target server with default setting.
      • Import the below registry key and apply it on the target server . Make sure you have full backup of registry.
      • Reboot the server.

    To enable this hotfix, follow these steps:
    1. Click Start, click Run, type regedit, and then press ENTER.
    2. Locate and then click the following registry subkey:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl
    3. On the Edit menu, point to New, and then click Key.
    4. Type the following name, and then press ENTER:
      FEATURE_PARSING_BRANDING_CMDLINE_FLAGS_KB941158
      Note We recommend that you type this value. Please remove trailing spaces if you plan to copy and paste this registry value.
    5. On the Edit menu, point to New, and then click DWORD Value.
    6. Type the asterisk symbol (*), and then press ENTER.
    7. On the Edit menu, click Modify.
    8. Type 1, and then click OK.
    9. Exit Registry Editor.

    To do the above work useing batch script , save the below code as a batch and run it on the target server. (Make sure KB and batch script should be in a same folder.)

    "cls
    echo
    ECHO.
    ECHO installing KB941158
    change user /install
    IE7-WindowsServer2003-KB941158-x86-ENU.exe /passive /norestart
    pause
    ECHO.
    ECHO Adding registry key

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_PARSING_BRANDING_CMDLINE_FLAGS_KB941158" /v "*" /d "1" /t REG_DWORD /f
    change user /execute
    quser
    pause
    logoff

    "
    If you are running the batch file from network share then plesae chnage the code a bit . Replace the

    IE7-WindowsServer2003-KB941158-x86-ENU.exe /passive /norestart
    line with

    start file://%3cnetwork-share%3e/IE7-WindowsServer2003-KB941158-x86-ENU.exe /passive /norestart

    Events with ID 333 are added to the System log on Windows server 2003 may cause citrix connection problem.

    Events with ID 333 are added to the System log on Windows server 2003
     
     
    Cause:
    This issue may occur when the Non Paged Memory or the Paged Pool Memory is temporarily insufficient. The system keeps recording such events until the computer is restarted, or the related hive is unloaded, even though the temporary memory insufficiency stops.
     
    As a result users won't be able to access published application and in sometimes unable to access the server via RDP.
     
    Resolution:
     
    Go to the following link to apply the Microsoft Hotfix WindowsServer2003-KB970054-x86-ENU.exe

    [Note: To apply this hotfix, the computer must have Windows Server 2003 Service Pack 1 or Service Pack 2 installed.]
     
     


     After installation you have to enable it by adding following registry value:

    Location : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
    Name     : RegistryFlushErrorSubside
    Type      : REG_DWORD
    Value     : 1 or 2

    If you set the value of the RegistryFlushErrorSubside entry to 1, the system only records one event 333 when the temporary memory insufficient occurs. If the value is set to 2, the system triggers a Stop error for diagnostic purpose.

    It is recommended to enter the value as 2.
     

    After updating the registry restart the server.

    Wednesday, January 12, 2011

    Error 1920. Service ‘Citrix SMA Service’ (Citrix SMA Service) failed to start. Verify that you have sufficient privileges to start system services

    Symptoms: Error 1920. Service ‘Citrix SMA Service’ (Citrix SMA Service)
    failed to start. Verify that you have sufficient privileges to start
    system services.



    Resolution :
    1. Check permissions to the following folder
      C:\Program Files\Citrix\SMA\Active
    2. Check the folder exists, if not create it. Otherwise the user account which is completing the PSE450W2K3R04 installation must have Full Control rights to this folder.

    The WMI provider namespace cannot be found on server 'SERVER'. (Message: Invalid namespace Error: 0x8004100E)

    The WMI provider namespace cannot be found" WBEM_E_INVALID_NAMESPACE 0x8004100e Error on Citrix


    Issue : When viewing the server health of a Presentation Server 4.5 server in Citrix Access Management Console the following error is reported:

     



    "The WMI provider namespace cannot be found on server 'SERVER'. (Message: Invalid namespace Error: 0x8004100E)"

    The following is also seen in the Application event log:

    Source: WSH
    Event ID: 1
    Citrix Monitoring Script Event 2
    Citrix MetaFrame Session In Down State:
    WMI error retrieving session object:
    Received error: 0x8004100e: Invalid namespace [WBEM_E_INVALID_NAMESPACE]

    Repairing the Citrix installation does not resolve the issue.

    Resolution :   If you receive this error you will need to recompile one or more of your Citrix .MOF files. A .MOF (Managed Object Format) file is the mechanism by which information about WMI classes is entered into the WMI Repository. It is possible that the class definitions currently in the Repository have somehow become corrupted; in that case, recompiling your .MOF files will cause those class definitions to be overwritten and replaced with the same, uncorrupted class definitions used when the operating system was originally installed.

    To recompile all Citrix .MOF files enter the following commands in a command prompt:

    C:
    CD "C:\Program Files\Citrix\System32\Citrix\WMI"
    for %i in (*.mof, *.mfl) do Mofcomp %i
     
     
    It may also be necessary to restart the Windows Management 
    Instrumentation Driver Extensions service, which will restart the 
    following services:
    
    
    
    
    
     - Citrix ADF Installer Service
    
    
     - Citrix Client Network
    
    
     - Citrix Encryption Service
    
    
     - Citrix Independent Management Architecture
    
    
     - Citrix MFCOM Service
    
    
     - Citrix XML Service
     

    Please save the below code as a batch file and run it on the victim server.

    "net stop winmgmt /y
    z:
    cd %systemroot%\system32\wbem
    rd /S /Q repository
    regsvr32 /s %systemroot%\system32\scecli.dll
    regsvr32 /s %systemroot%\system32\userenv.dll
    mofcomp cimwin32.mof
    mofcomp cimwin32.mfl
    mofcomp rsop.mof
    mofcomp rsop.mfl
    for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
    for /f %%s in ('dir /b *.mof') do mofcomp %%s
    for /f %%s in ('dir /b *.mfl') do mofcomp %%s

    net start ccmexec
    cd %programfiles%\citrix\system32\citrix\wmi
    for /f %%s in ('dir /b *.mof *.mfl') do mofcomp %%s


    "

    Enjoy :)