Jere's Techblog

Verify Citrx HostedMachineID with VmWare Hypervisor

Sometimes the HostedMachineID of Citrix does not match that of VmWare. This is often the case when cloning or moving machines. In Citrix Studio you will see the Powerstate of this machines as unknow and you can’t do any VM actions like reboot in the console.

With this script snippet it can be checked. To do this the variable “Broker” must be adjusted in the Script and the PowerCli and CitrixModule (BrokerSnapIn) must be loaded. Furthermore, the connection to the vCenter must be initiated via “Connect-VIServer vCName“.

#25.09.2019by J.Kühnis - Verfiy HostedMachineID with VmWare ESXi Hypervisoer

$Broker = "Enter your BrokerName"
$Brokermachines = Get-BrokerMachine -AdminAddress $Broker | Select MachineName,DNSName,HostedMachineID

Foreach ($Machine in $Brokermachines){
    IF(get-vm $Machine.DnsName -ErrorAction SilentlyContinue){
        IF($Machine.HostedMachineID -eq (Get-View -id (get-vm $machine.DNSName).id).config.uuid){
            Write-Host $Machine.DnsName "HostedMachineID is matching" $Machine.HostedMachineId -ForegroundColor Green
        }Else{
            Write-host $Machine.DnsName "Mismatch ID: VmWare UUID =" (Get-View -id (get-vm $machine.DNSName).id).config.uuid "; Citrix HostedMachineID =" $Machine.HostedMachineID -ForegroundColor Yellow
        }

    }Else{
        Write-host $Machine.DnsName "MachineName not Found on ESXi" -ForegroundColor Yellow
    }
}

Now that the machines have been read out, the connections can be fixed.

vCenter Cert thumbprint update:

# Open an admin POSH console, load the Citrix Modules (asnp citrix*) and cd to XDHyp:/Connections and run ls. Check the SSLThumbprints entry.
asnp citrix*
cd XDHyp:/Connections
ls
Set-Item -LiteralPath "XDHyp:\Connections\vCenters Name" -sslthumbprint "123456789ABCD123456789ABCDE123456789ABCD" -hypervisorAddress https://vcenter-name/sdk

The letters in SSL-Thumbprint must be uppercase.

In this blog the problem is also discussed in detail:

Continue reading...

Get InUse Publishings in ApplicationGroup

Here is a code snippet to read the active publishings attached to a deliverygroup. These are only the publishings which are in an application group.

#by JKU 04.09.2019
Add-PSSnapin *

$exporttime = get-date -Format ("dd.MM.yyyy_hh.mm.ss")
$exportpath = "C:\temp\inUsePublishings_" + $exporttime + ".csv"
$ArryinUsePublishings = @()
$AGUids = (Get-BrokerApplicationGroup * | ?{($_.AssociatedDesktopGroupUids).count -ge 1}).uid

Foreach($CTXAPP in (Get-BrokerApplication * -MaxRecordCount 1000000)){
    IF(($CTXAPP.AssociatedApplicationGroupUids | % {$AGUids -contains $_}) -contains $true){
    $ArryinUsePublishings += $CTXAPP
    }
}
$ArryinUsePublishings | export-csv $exportpath
Write-host "File Exported to $exportpath"

Continue reading...

Scriptblock to check PVS Connection

On the fly, I found no way to check which PVS servers & service are online. This is especially important if I want to issue PVS commands from Remote / Orchestrated. Enclosed I have made a small script block to check this. It is certainly not the best way, but it works. One possibility would be to retrieve the status of the PVS-services, but it is unclear whether one can actually connect to the servers trough PVS commands.

#by JKU 09.08.2019
$error.clear()
$k.clear()
$PVSConnectionServers.clear()

$PVSConnectionServers = @("PVS-Server01", "PVS-Server02")

$k = 0
Foreach($PVS_Server in $PVSConnectionServers){
    Set-PvsConnection $PVS_Server
    if($Error -match $PVS_Server){
        #Check Next Server
        $k++
        IF($k -eq $PVSConnectionServers.Count){
            Write-Warning "ALL PVS Servers are not reachable, stop script! $PVSConnectionServers"
            Return
        }
    }Else{
        Break
    }
}

Write-Host "Connecting to $PVS_Server"
Continue reading...

Citrix DeliveryController DB rejoin; The operation could not be performed because of a configuration logging error.

To rejoin a Citrix Broker into a existing or migrated Databese, there are a lot of usefull articles:

https://support.citrix.com/article/CTX212941

https://support.citrix.com/article/CTX216504

Problem Cause

In some cases you can’t configure the Monitor and Log DataStore Connections after you deleted the Connection with:

Set-MonitorDBConnection -DataStore Monitor -DBConnection $null -force
Set-MonitorDBConnection -DBConnection $null -force
Set-LogDBConnection -DataStore Logging -DBConnection $null -force
Set-LogDBConnection -DBConnection $null -force

If you like to rejoin the Connection with the following command:

Set-LogDBConnection -DataStore Logging -DBConnection $csLogging

You get the following error:

Set-LogDBConnection : The operation could not be performed because of a configuration logging error.
At line:1 char:1


Set-LogDBConnection -DataStore Logging -DBConnection $csLogging
~~~~~~~~~~~~~~~CategoryInfo : InvalidOperation: (:) [Set-LogDBConnection], InvalidOperationException
FullyQualifiedErrorId : Citrix.XDPowerShell.Status.ConfigurationLoggingError,Citrix.ConfigurationLogging.Sdk.DataStore.Commands.SetLogDBConnectionCommand

Solution 1

There is a possibility to disable the settings before nullify the connections:

Set-LogSite -State "Disabled"
Set-MonitorConfiguration -DataCollectionEnabled $False

then go ahead with this article https://support.citrix.com/article/CTX216504 and reenable the Settings; run those commands as last step:

Set-LogSite -State "Enabled"
Set-MonitorConfiguration -DataCollectionEnabled $true

Solution 2

Just use the “-force” parameter while setting up the DB Connection. Afterwards i recommend to reboot the Broker Server.

Set-LogDBConnection -DataStore Logging -DBConnection $csLogging -force
Set-MonitorDBConnection -DataStore Monitor -DBConnection $csMonitoring -force
Continue reading...

Invoke Command on Specified MachineCatalog and DeliveryGroup

The nice thing about Powershell and the modules/API to other technologies is that you can do simple queries and have a big effect.

The following example starts a service for specified machines in a Citrix 7.x environment.

#by J.Kühnis 06.03.2019
Add-PSSnapin *
$machines = (Get-BrokerMachine * -AdminAddress my.broker.fqdn |
 where-object {($_.CatalogName -match "someMC*") -and ($_.DesktopGroupName -eq "someDG")}).DNSName

Foreach ($machine in $Machines)
 {Write-Host $machine -ForegroundColor Yellow
 invoke-command -ComputerName $machine -ScriptBlock {get-service -name cpsvc | Start-Service} }

Continue reading...

Delete Citrix Worker from Studio and vCenter

With this script one or more servers can be deleted from the Citrix DeliveryController (Citrix Studio) and from the ESXi/vCenter.

To use The Script some variables and values need to be adjusted like the name of the Citrix DeliveryController and vCenter.
Vmware (PowerCLI) and Citrix (SDK) powershellmodules need to be installed.

This only works if the VM name is identical to the Worker Server DNS name. If this is the case, the following string can be deleted in the script [-replace “.FQDN.address”,””]

In my case, the name of the VM is only the “hostname” of the machine and not the DNSname. So the script removes the FQDN name, in order to use the script successfully, this must also be adjusted.

Import-Module *
Add-PSSnapin *

$DeliveryController = "someBrokerDNSName"
Connect-viserver "some vCenter"


Get-BrokerMachine -DNSName anySevernames* -AdminAddress $DeliveryController |  %{
    
    #Delete & Remove From Citrix Studio
    Remove-BrokerMachine $_ -DesktopGroup $_.DesktopGroupName
    Remove-BrokerMachine $_ -Force

    #Delete Permanently from vCenter
    remove-vm ($_.DNSName -replace ".FQDN.Adress","") -DeletePermanently -Confirm:$false

    write-host $_.DNSName -ForegroundColor Green  #Write ServerName

}
Continue reading...

Backup & Restore Citrix Storefront Configuration with Powershell

Backup

Ensure you’re running Powershell as Administrator and you loaded the StoreFront Powershell Modules:

Get-Module "Citrix.StoreFront.*" -ListAvailable | Import-Module

Export STF Configuration

Export-STFConfiguration -TargetFolder "C:\temp" -ZipFileName "31.01.2019_STF_Backup" -NoEncryption -Confirm:$false

The IIS settings will be not saved. For example, IIS bindings to the default web site or HTTP Redirect entries that were made, will not be imported when you restore the backup ZipFile.

You can also take an IIS Configuration Backup.

Unfortunately, not all settings will be exported from the IIS here either…
Therefore I recommend to make a backup of the server (VM Snapshot or similar) another method is to keep an installation documentation about the manual IIS configuration and to recheck the config after a configrestore.

$a = [datetime]::Today.ToString('dd.MM.yyy')

function IISBackupCreate {cmd /c C:\WINDOWS\System32\inetsrv\appcmd.exe add backup $a}
IISBackupCreate

Restore

Citrix Config Restore:

Import-STFConfiguration -ConfigurationZip C:\Temp\31.01.2019_STF_Backup.zip

Afterwards you have to propagate the Storefront Configuration.


Restore IIS Config:

To restore IIS Configuration ensure you define the variable “$a” in the script above with the name of the Backupfolder.

You can find those Folders under “C:\WINDOWS\System32\inetsrv\backup”

#$a = "20190201T132905"      
function IISBackupRestore {cmd /c C:\WINDOWS\System32\inetsrv\appcmd.exe restore backup $a}
IISBackup

iisreset

IIS Custom settings are not synchronized with Storefront Propagate function. The restore must be done on every storefront server.

Continue reading...

Citrix Broker Count Users

Here are some Powershell possibilities to get the amount of sessions or Citrix’s Unique sessions.

Get all Citrix Sessions:

(Get-BrokerSession -MaxRecordCount 100000).count

Get the numbers of sessions per user:

Get-BrokerSession -MaxRecordCount 100000 | group-object UserName | Sort-Object -Descending count

You will get a list with Usernames (SamAccountName) and the Number of Sessions per User

Get the amount of logged in Users:

(Get-BrokerSession -MaxRecordCount 100000 | group-object UserName).count
Continue reading...