Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#####
- Stand alone XenDesktop MCS VDA Installer (XenServer)
- Written by David Ott
- I wrote this script because I have over 100 stand alone VDAs running on XenServer in my environment. Upgrading the VDA software
- becomes a huge pain as you can imagine.
- ***** Pay attention to anything marked with ##### as you will need to customize the script for
- your environment.*****
- This will only work on Windows VDAs!!
- Requirements:
- XenCenter installed on the machine you run the script from
- Know the local admin credentials for your MCS desktops
- VDA Cleanup Utility (google it and download the latest version)
- ISO library with the XA/XD .iso available
- How it works:
- 1. You can query your delivery controller for all VDAs you wish to upgrade, or you can run it against individual VDAs
- I'd suggest running it against individual VDAs until you are comfortable with the results. Noted in the first part of the
- script after the BEGIN line
- 2. Once the script knows which computer(s) you wish to upgrade it will create 2 powershell scripts on the C:\ drive of each
- computer, and 2 scheduled tasks to run them. It will also attach the XA/XD .iso you specify to the VM.
- 3. The first scheduled task will run as system, add auto logon information into the registry, and restart the computer
- 4. The second scheduled task (the meat and potatoes) will run at logon (local admin user set to auto logon). It will uninstall
- any existing VDA using the VDA Cleanup Utility (always use the latest one Citrix has available), install the new VDA from
- the attached DVD drive (session recording optional), eject the DVD after install, clean up the auto logon info/files, and reboot.
- #####>
- #####***** BEGIN *****#####
- ##### Remove comment start from the line below to allow the script to grab every MCS desktop in a specified delivery group
- <#$computers = Invoke-Command -ComputerName <your delivery controller> -ScriptBlock {
- asnp citrix*
- ##### Edit the line below with the MCS desktop group name, and the current agent version
- Get-BrokerDesktop -MaxRecordCount 1000 -DesktopGroupName "DESKTOP GROUP NAME" -Filter {(agentversion -lt "7.16") -and (sessionstate -ne "active")} | select -expand dnsname
- ##### If you use this remove the end comment below
- }#>
- ##### If you do not want to run this script against an individual computer enter the computer name below
- ##### (this is how you should run it while testing!)
- ##### If you are querying the delivery controller for all MCS desktops in a delivery group comment the line below
- ##### by adding "#" before $computers
- $computers = "Individual Computer"
- $xe = "c:\program files (x86)\citrix\xencenter\xe.exe"
- if (!(test-path $xe)) {
- $xe = "c:\program files\citrix\xencenter\xe.exe"
- if (!(test-path $xe)) {
- Write-Host "Please install XenCenter before continuing."
- break
- }
- }
- $pass = "XenServer Root Password" #####
- $master = "XenServer Master IP Address" #####
- $vms = &$xe vm-list -s $master -u root -pw $pass params=name-label | %{
- ($_ -split ": ")[1]
- }
- $vms = $vms | ?{$_ -ne $null}
- $cd = "XenApp_and_XenDesktop_7_15_1000.iso" ##### set the correct iso name
- ##### Script1 is the first script to get executed on the remote VDA. It adds in autologon info and reboots the VDA
- ##### so that the main script will run at logon of the local admin
- $script1 = @"
- ##### Change the log name for each version (also later)
- `$log = "c:\upgrade715_1.log"
- if (!(test-path `$log)) {
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "1" -type string
- ##### Edit the local admin password to match your environment
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "LOCAL ADMIN PASSWORD" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Administrator" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value "computername" -type string
- "Start "+(get-date).ToString() | out-file `$log
- Restart-Computer -force
- break
- }
- "@
- $script = @"
- ##### cleanup function - runs after all done
- function cleanup {
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "0" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value `$null -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "PowerUser" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value `$null -type string
- & schtasks /delete /tn kickoff /f
- & schtasks /delete /tn upgrade /f
- ri c:\upgrade.ps1
- ri c:\upgradetmp.ps1
- ri c:\VDACleanupUtility.exe -force
- ri "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Citrix" -recurse -force
- }
- `$culog = "`$env:temp\Citrix\VdaCleanup\CleanupToolLog.txt"
- ##### Change the log name for each version - match the name from $script1
- `$log = "c:\upgrade715_1.log"
- ##### if the log file doesn't exist then something went wrong with $script1
- if (!(test-path `$log)) {
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "1" -type string
- ##### Edit the local admin password to match your environment
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "LOCAL ADMIN PASSWORD" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Administrator" -type string
- sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value "computername" -type string
- "Start "+(get-date).ToString() | out-file `$log
- Restart-Computer -force
- break
- }
- `$gc = gc `$log
- ##### Starts VDA Removal if it hasn't started
- if (`$gc -match "vda removal" -eq `$false) {
- "vda removal start "+(get-date).tostring() | Out-File `$log -Append
- ##### removes any previous vda cleanup logs
- if (test-path `$culog) {ri (split-path `$culog -parent) -recurse -force}
- `$p = Start-Process -FilePath C:\VDACleanupUtility.exe -ArgumentList "/silent" -passthru
- wait-process `$p.id
- break
- } else {
- ##### detects if the vda cleanup is continuing after reboot
- if (get-process vdacleanuputility -ea silentlycontinue) {
- "vda removal continue "+(get-date).ToString() | Out-File `$log -Append
- get-process vdacleanuputility -ea silentlycontinue | wait-process
- }
- if ((gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce) -match "citrixvdacleanup") {
- break
- }
- ##### If the vda cleanup utility has finished the script will get to this point - it waits for the log to show that
- ##### the utility has attempted to upload usage info to citrix - indicating it has finished
- while ((gc `$culog -last 1) -notlike "*upload*") {start-sleep -s 1}
- `$dvd = (gwmi win32_logicaldisk | ?{`$_.volumename -like "XA*"} | select -expand deviceid)+"\"
- `$setup = Join-Path `$dvd "x64\XenDesktop Setup\XenDesktopVDASetup.exe"
- ##### Edit your delivery controller(s) - separate by space
- `$installargs = "/quiet /noreboot /components VDA,PLUGINS /controllers ``"deliverycontroller1.yourdomain.com deliverycontroller2.yourdomain.com``" /enable_remote_assistance /enable_hdx_ports /optimize /enable_real_time_transport /enable_framehawk_port /masterimage /virtualmachine /exclude ``"Personal vDisk``""
- "Install VDA "+(get-date).tostring() | out-file `$log -append
- Start-Process `$setup -ArgumentList `$installargs -Wait
- ##### Session Recording install (optional) remove comment brackets to enable the install. Remember that MSMQ-HTTP is a
- ##### prerequisite. Depending on which OS you are using there are different commands to install it.
- ##### Since I installed it on my master image before deploying the stand alone MCS VDAs I didn't add this in
- <#
- `$sesins = Join-Path `$dvd "x64\Session Recording\SessionRecordingAgentX64.msi"
- ##### Assuming all ports are default update the SESSIONRECORDINGSERVERNAME
- `$sesinsargs = "/quiet INSTALLLOCATION=``"C:\Program Files\Citrix``" ARPSYSTEMCOMPONENT=``"1``" MSIFASTINSTALL=``"1``" MSIRMSHUTDOWN=``"2``" METAINSTALLER=``"1``" SESSIONRECORDINGSERVERNAME=``"FQDN OF YOUR SESSION RECORDING SERVER``" SESSIONRECORDINGBROKERPROTOCOL=``"HTTPS``" SESSIONRECORDINGBROKERPORT=``"443``" CLOUD=False REBOOT=ReallySuppress"
- "Install Session Recording "+(get-date).tostring() | out-file `$log -append
- start-process `$sesins -argumentlist `$sesinsargs -wait
- #>
- ##### Ejects the DVD
- `$diskmaster = New-Object -ComObject imapi2.msftdiscmaster2
- `$diskrecorder = new-object -ComObject imapi2.msftdiscrecorder2
- `$diskrecorder.initializediscrecorder(`$diskmaster)
- `$diskrecorder.ejectmedia()
- ##### Cleanup and restart
- cleanup
- restart-computer -force
- }
- "@
- foreach ($computer in $computers) {
- $sel = $vms | ?{$computer -like "$_`*"}
- if ($sel -eq $null) {break}
- &$xe vm-cd-insert -s $master -u root -pw $pass cd-name="$cd" vm="$sel"
- ##### Creates the script files on the remote computer
- $script -replace "computername",$computer| Out-File "\\$computer\c`$\upgrade.ps1"
- $script1 -replace "computername",$computer| Out-File "\\$computer\c`$\upgradetmp.ps1"
- ##### Edit the source of the VDA Cleanup Utility
- cp \\server\share\VDACleanupUtility\VDACleanupUtility.exe \\$computer\c`$
- ##### You will receive an error on the first scheduled task install due to the date/time - disregard
- Invoke-Command -ComputerName $computer -ScriptBlock {
- & schtasks /create /tn kickoff /tr "powershell.exe -executionpolicy unrestricted -file c:\upgradetmp.ps1" /sc ONCE /sd "12/12/2000" /st 12:00 /ru SYSTEM /rl highest
- & schtasks /create /tn upgrade /tr "powershell.exe -executionpolicy unrestricted -file c:\upgrade.ps1" /sc ONLOGON /ru Administrator /rl highest
- & schtasks /run /tn kickoff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement