Last active
June 15, 2017 10:26
-
-
Save SveinErik/e03d2c6279f7ff7aa9112dbbdba06cef to your computer and use it in GitHub Desktop.
Change/Update CommandLineExecutable and WorkingDirectory on published apps in Citrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################################# | |
# Change/Update Applicationpath (CommandLineExecutable) and WorkingDirectory on published apps | |
# Example \\11fil05\Program\Sys\Tieto\Ressursstyring\RS_Ajour.exe og \\11fil05\Program\Sys\Tieto\Ressursstyring\ | |
# to \\11fil02\Program\Sys\Tieto\Ressursstyring\RS_Ajour.exe og \\11fil02\Program\Sys\Tieto\Ressursstyring\ | |
# | |
# 15.16.2017 - SES | |
# Citrix doc: https://developer-docs.citrix.com/projects/delivery-controller-sdk/en/latest/Broker/Set-BrokerApplication/ | |
############################################################################################# | |
# Adding Citrix Snapins | |
Add-PSSnapin Citrix* | |
# Declare the string that will be replaced/updated | |
$searchTerm = "\\11fil05" | |
$replaceWith = "\\11fil02" | |
# Get only one specified application by name: | |
#$apps = Get-BrokerApplication -ApplicationName "RS_Sikkerhet" | |
# Get all apps: | |
$apps = Get-BrokerApplication -MaxRecordCount 2147483647 | |
# Create counters for whats updated: | |
$counterCommandLine = 0 | |
$counterWorkingDir = 0 | |
foreach($app in $apps) | |
{ | |
#Hold the current app name, to be used in the catch-block | |
$currentApp = $app.ApplicationName | |
try{ | |
if(( ($app.CommandLineExecutable.Contains($searchTerm)) -or ($app.WorkingDirectory.Contains($searchTerm)) )) | |
{ | |
Write-Host ("Found 1 or more occurences in " + $app.ApplicationName + ", starting replace..") -ForegroundColor Green | |
#Perform checks to find out what we need to update | |
if( ($app.CommandLineExecutable.Contains($searchTerm) -and $app.WorkingDirectory.Contains($searchTerm)) ) | |
{ | |
Write-Host "Both needs to be updated" -ForegroundColor Cyan | |
$commandLineExecutable = $app.CommandLineExecutable.Replace($searchTerm,$replaceWith) | |
$workingDirectory = $app.WorkingDirectory.Replace($searchTerm,$replaceWith) | |
$counterCommandLine++ | |
$counterWorkingDir++ | |
#Write-host $commandLineExecutable ", " $workingDirectory #Write current settings | |
Write-Host ("Updating " + $app.ApplicationName) -ForegroundColor Yellow | |
Set-BrokerApplication -InputObject $app -CommandLineExecutable $commandLineExecutable -WorkingDirectory $workingDirectory | |
} | |
elseif($app.CommandLineExecutable.Contains($searchTerm)) | |
{ | |
Write-Host "Only CommandLineExecutable needs to be updated" -ForegroundColor Cyan | |
$commandLineExecutable = $app.CommandLineExecutable.Replace($searchTerm,$replaceWith) | |
$counterCommandLine++ | |
#Write-host $commandLineExecutable | |
Write-Host ("Updating " + $app.ApplicationName) -ForegroundColor Yellow | |
Set-BrokerApplication -InputObject $app -CommandLineExecutable $commandLineExecutable | |
} | |
elseif($app.WorkingDirectory.Contains($searchTerm)) | |
{ | |
Write-Host "Only WorkingDirectory needs to be updated" -ForegroundColor Cyan | |
$workingDirectory = $app.WorkingDirectory.Replace($searchTerm,$replaceWith) | |
$counterWorkingDir++ | |
#Write-host $workingDirectory | |
Write-Host ("Updating " + $app.ApplicationName) -ForegroundColor Yellow | |
Set-BrokerApplication -InputObject $app -WorkingDirectory $workingDirectory | |
} | |
} | |
} | |
catch{ | |
Write-Warning ('The following app probably does not contain a value for eihter CommandLineExecutable or WorkingDirectory: ' + $currentApp + ' - ' + $_) | |
} | |
} | |
Write-Host("##################################") -ForegroundColor Green | |
Write-Host ("Finished! Updated " + $counterCommandLine + " CommandLineExecutable, and " + $counterWorkingDir + " WorkingDirectory") -ForegroundColor Green | |
Write-Host("##################################") -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment