Jere's Techblog

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...

Powershell Core installation on Linux

There are several ways to install Powershell on Linux/Max/Windows. The usual way is to download the installer package:

https://github.com/PowerShell/PowerShell/releases/

I prefer to add the package repository to the System to keep the installation up2date when you update your linux system/apps.

Microsoft has a very nice Documentation about the Powershell install:

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6

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...

Visual Studio Code

One of my favorite editors for editing Powershell scripts is Visual Studio Code. Mircosoft’s OpenSource Code Editor, launched in 2016, is a wonderful editor and the biggest advantage is that it works on Windows, Linux and Mac.

In this article I want to show some advantages why I prefer this editor to the classic Powershell_Ise, Atom Editor and Notepad++. I also show useful addons and editor settings.

Okay first of all i’ll show you why

At the beginning I will show you the advantages of the editor:

  • The editor is very fast (no lags) and it starts very fast
  • The editor is with approx. 180MB installation size relatively slim in contrast to Visual Studio
  • The editor supports various programming and scripting languages, which can be installed using extensions.
  • Many Addons/Extensions (Debugger, DebugConsole, ColorEditors, Autocorrection, Sourcecontrol, GIT, TFS Server, Docker, various Azure Tools and Connections)
  • Code can be executed within the editor.
  • Integrated Terminal Console
  • Many configuration options (autosave, color selection, editor behavior, code arrangement and much more).
  • Command Explorer
  • Various color themes for the editor itself (dark / light, much based on Visual Studio)
  • Configuration can be easily done using .json files or GUI
  • Has a very large user community and is strongly pushed by Microsoft.

Distinctive differences to Visual Studio Editor:

  • Visual Studio Code organizes itself according to folder structures (file system) and not like Visual Studio with “Projects”
  • No integrated editor for Windows WPF/Windows Form GUI’s.
  • No Enterprise Debugging (CPU Runtime)

Those are my prefferd Custom Settings:

I have made the following setting in the JSON file (User Settings) to make the scripten more pleasant.

“powershell.integratedConsole.focusConsoleOnExecute”: false,

“powershell.scriptAnalysis.enable”: true,

“powershell.codeFormatting.openBraceOnSameLine”: true

Continue reading...

Test TCP Networkports with Powershell

http://portquiz.net/ is a great Website to test any outbound TCP Port.

Of course there are a lot Programm who can check which TCP Ports are open. But i’ll show you a way how you can test the Ports with Powershell.
$16bitint = 1..65535 
foreach ($port in $16bitint) {
    IF (Test-NetConnection -ComputerName portquiz.net -InformationLevel Quiet -Port $port){
          Write-Host $port 
    } 
}

Continue reading...

Compare AD-GroupMember

Example:

JKCompare-ADGroupMemeber -Group1 GROUPNAME1 -Group2 GROUPNAME2

Optional Parameter:

-IncludeEqual yes

#13.11.2018 Jeremias Kühnis

Function JKCompare-ADGroupMemeber{
[CmdletBinding()]
Param(
    [Parameter(Mandatory=$true)]
    [string]$Group1,
    
    [Parameter(Mandatory=$true)]
    [string]$Group2,

    [Parameter(Mandatory=$false)]
    [ValidateSet("yes", "no")]
    [string]$IncludeEqual
)

IF($IncludeEqual -eq "Yes"){
    diff (Get-ADGroupMember $Group1) (Get-ADGroupMember $Group2) -Property 'SamAccountName' -IncludeEqual
}Else{
    diff (Get-ADGroupMember $Group1) (Get-ADGroupMember $Group2) -Property 'SamAccountName'
}

Write-Host "#############################################" -ForegroundColor Cyan
Write-Host "== This user is in both groups (If option is enabled)."
Write-Host "=> This user is in the second group ($group2)."
Write-Host "<= This user is in the first group ($group1)."
Write-Host "#############################################" -ForegroundColor Cyan
}
Continue reading...

Remove AD-Group on certain Users

This script is very handy in dayli business, when you need to remove multiple users from an AD-Group.

In the userlist the users can be specified with the samAccountName.

Of course there is the possibility to fill “$UserList” variable with a list e.g. a CSV-File. In this case you can Use the function “Import-Csv” which is an out of the Box Powershell feature.

#13.11.2018 by Jeremias Kühnis
#Remove AD-Groupmemership

$ADGroup = "someAdGroupName"

$Userlist = @(
"SamAccountName1"
"SamAccountName2"
"SamAccountName3"
)

$Userlist | % {Remove-ADGroupMember -Identity $ADGroup -Members $_ -Confirm:$false}
Continue reading...