Public/Add-CitrixLicensing.ps1
function Add-CitrixLicensing { <# .SYNOPSIS Adds a Citrix Licensing Load Balancing configuration to your Citrix ADC. .DESCRIPTION Adds a Citrix Licensing Load Balancing configuration to your Citrix ADC. The configuration data for this function is driven by the "Licensing" section of the JSON file passed in. .PARAMETER JSONFile The JSON file containing the data to be used to configure the Citrix Licensing GSLB configuration. .NOTES Creation Date: 29/03/2018 .CHANGE CONTROL Name Version Date Change Detail David Brett 1.0 29/03/2018 Function Creation .EXAMPLE Add-CitrixLicensing -JSONFile C:\CitrixADC\CitrixADC-Build.json Add-CitrixLicensing -JSONFile C:\CitrixADC\CitrixADC-Build.json -Verbose #> [CmdletBinding()] Param ( [parameter(Mandatory = $false, ValueFromPipeline = $true)][string[]]$JSONFile ) begin { $StartTime = (Get-Date) if (test-path $JSONfile) { try { $JSON = Get-Content -Raw -Path $JSONfile | ConvertFrom-Json -ErrorAction Stop } catch { throw "Error reading JSON. Please Check File and try again." } } # Read in data from the JSON File $MonitorPrefix = $json.global.MonitorPrefix $ServicePrefix = $json.global.ServicePrefix $vServerPrefix = $json.global.vServerPrefix # Generate Citrix ADC Credentials $SecurePassword = ConvertTo-SecureString $JSON.Global.ADCPassword -AsPlainText -Force $ADCCredentials = New-Object System.Management.Automation.PSCredential ($JSON.Global.ADCUserName, $SecurePassword) } process { Write-Verbose "Starting to add Citrix Licensing Load Balancing Configuration to the Citrix ADC" # Connect to the Citrix ADC Connect-CitrixADC -IPAddress $JSON.Global.ADCIP -Credential $ADCCredentials # Add Citrix Licensing server to ADC foreach ($Server in $json.licensing.servers) { Add-ADCServer -ServerName $server.dnsname -ServerIP $server.ipaddress } # Add 4 monitoring to check the status of the Citrix Licensing Server Add-ADCCustomTCPMonitor -MonitorName $MonitorPrefix'citrix_licensing_27000' -MonitorPort 27000 Add-ADCCustomTCPMonitor -MonitorName $MonitorPrefix'citrix_licensing_7279' -MonitorPort 7279 Add-ADCCustomTCPMonitor -MonitorName $MonitorPrefix'citrix_licensing_8082' -MonitorPort 8082 Add-ADCCustomTCPMonitor -MonitorName $MonitorPrefix'citrix_licensing_8083' -MonitorPort 8083 # Add the ADC Service for Citrix Licensing foreach ($Server in $json.licensing.servers) { Add-ADCService -ServiceName $ServicePrefix'citrix_licensing' -ServiceType "TCP" -ServicePort 65535 -ServerName $server.dnsname } # Bind the 4 monitors to the new service Set-ADCMonitorToService -ServiceName $ServicePrefix'citrix_licensing' -MonitorName $MonitorPrefix'citrix_licensing_27000' Set-ADCMonitorToService -ServiceName $ServicePrefix'citrix_licensing' -MonitorName $MonitorPrefix'citrix_licensing_7279' Set-ADCMonitorToService -ServiceName $ServicePrefix'citrix_licensing' -MonitorName $MonitorPrefix'citrix_licensing_8082' Set-ADCMonitorToService -ServiceName $ServicePrefix'citrix_licensing' -MonitorName $MonitorPrefix'citrix_licensing_8083' # Add the new Load Balancing Virtual Server Add-ADCLoadBalancingvServer -vServerName $vServerPrefix'citrix_licensing' -vServerType "TCP" -vServerIPv4 $json.Licensing.LicenseServerVirtualServerIP -vServerPort 65535 # Bind the new service to the Load Balancing vServer Set-ADCServiceTovServer -vServerName $vServerPrefix'citrix_licensing' -ServiceName $ServicePrefix'citrix_licensing' # Disconnect from the Citrix ADC Disconnect-CitrixADC Write-Verbose "Finished adding Citrix Licensing Load Balancing Configuration to the Citrix ADC" } end { $EndTime = (Get-Date) Write-Verbose "Add-CitrixLicensing finished." Write-Verbose "Elapsed Time: $(($EndTime-$StartTime).TotalMinutes) Minutes" Write-Verbose "Elapsed Time: $(($EndTime-$StartTime).TotalSeconds) Seconds" } } |