Advertisement
david62277

Stand Alone MCS VDA Upgrade (XenServer)

Dec 15th, 2017
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#####
  2. Stand alone XenDesktop MCS VDA Installer (XenServer)
  3. Written by David Ott
  4. I wrote this script because I have over 100 stand alone VDAs running on XenServer in my environment.  Upgrading the VDA software
  5. becomes a huge pain as you can imagine.  
  6.  
  7. ***** Pay attention to anything marked with ##### as you will need to customize the script for
  8. your environment.*****
  9.  
  10. This will only work on Windows VDAs!!
  11. Requirements:
  12. XenCenter installed on the machine you run the script from
  13. Know the local admin credentials for your MCS desktops
  14. VDA Cleanup Utility (google it and download the latest version)
  15. ISO library with the XA/XD .iso available
  16.  
  17. How it works:
  18. 1. You can query your delivery controller for all VDAs you wish to upgrade, or you can run it against individual VDAs
  19. I'd suggest running it against individual VDAs until you are comfortable with the results.  Noted in the first part of the
  20. script after the BEGIN line
  21. 2. Once the script knows which computer(s) you wish to upgrade it will create 2 powershell scripts on the C:\ drive of each
  22. computer, and 2 scheduled tasks to run them.  It will also attach the XA/XD .iso you specify to the VM.
  23. 3. The first scheduled task will run as system, add auto logon information into the registry, and restart the computer
  24. 4. The second scheduled task (the meat and potatoes) will run at logon (local admin user set to auto logon).  It will uninstall
  25. any existing VDA using the VDA Cleanup Utility (always use the latest one Citrix has available), install the new VDA from
  26. the attached DVD drive (session recording optional), eject the DVD after install, clean up the auto logon info/files, and reboot.
  27.  
  28.  
  29. #####>
  30.  
  31.  
  32. #####***** BEGIN *****#####
  33. ##### Remove comment start from the line below to allow the script to grab every MCS desktop in a specified delivery group
  34. <#$computers = Invoke-Command -ComputerName <your delivery controller> -ScriptBlock {
  35. asnp citrix*
  36. ##### Edit the line below with the MCS desktop group name, and the current agent version
  37. Get-BrokerDesktop -MaxRecordCount 1000 -DesktopGroupName "DESKTOP GROUP NAME" -Filter {(agentversion -lt "7.16") -and (sessionstate -ne "active")} | select -expand dnsname
  38. ##### If you use this remove the end comment below
  39. }#>
  40. ##### If you do not want to run this script against an individual computer enter the computer name below
  41. ##### (this is how you should run it while testing!)
  42. ##### If you are querying the delivery controller for all MCS desktops in a delivery group comment the line below
  43. ##### by adding "#" before $computers
  44. $computers = "Individual Computer"
  45. $xe = "c:\program files (x86)\citrix\xencenter\xe.exe"
  46. if (!(test-path $xe)) {
  47. $xe = "c:\program files\citrix\xencenter\xe.exe"
  48. if (!(test-path $xe)) {
  49. Write-Host "Please install XenCenter before continuing."
  50. break
  51. }
  52. }
  53. $pass = "XenServer Root Password" #####
  54. $master = "XenServer Master IP Address" #####
  55. $vms = &$xe vm-list -s $master -u root -pw $pass params=name-label | %{
  56. ($_ -split ": ")[1]
  57. }
  58. $vms = $vms | ?{$_ -ne $null}
  59. $cd = "XenApp_and_XenDesktop_7_15_1000.iso" ##### set the correct iso name
  60. ##### Script1 is the first script to get executed on the remote VDA.  It adds in autologon info and reboots the VDA
  61. ##### so that the main script will run at logon of the local admin
  62. $script1 = @"
  63. ##### Change the log name for each version (also later)
  64. `$log = "c:\upgrade715_1.log"
  65. if (!(test-path `$log)) {
  66. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "1" -type string
  67. ##### Edit the local admin password to match your environment
  68. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "LOCAL ADMIN PASSWORD" -type string
  69. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Administrator" -type string
  70. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value "computername" -type string
  71. "Start "+(get-date).ToString() | out-file `$log
  72. Restart-Computer -force
  73. break
  74. }
  75. "@
  76. $script = @"
  77. ##### cleanup function - runs after all done
  78. function cleanup {
  79. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "0" -type string
  80. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value `$null -type string
  81. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "PowerUser" -type string
  82. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value `$null -type string
  83. & schtasks /delete /tn kickoff /f
  84. & schtasks /delete /tn upgrade /f
  85. ri c:\upgrade.ps1
  86. ri c:\upgradetmp.ps1
  87. ri c:\VDACleanupUtility.exe -force
  88. ri "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Citrix" -recurse -force
  89. }
  90. `$culog = "`$env:temp\Citrix\VdaCleanup\CleanupToolLog.txt"
  91. ##### Change the log name for each version - match the name from $script1
  92. `$log = "c:\upgrade715_1.log"
  93. ##### if the log file doesn't exist then something went wrong with $script1
  94. if (!(test-path `$log)) {
  95. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value "1" -type string
  96. ##### Edit the local admin password to match your environment
  97. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "LOCAL ADMIN PASSWORD" -type string
  98. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Administrator" -type string
  99. sp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultDomainName -Value "computername" -type string
  100. "Start "+(get-date).ToString() | out-file `$log
  101. Restart-Computer -force
  102. break
  103. }
  104. `$gc = gc `$log
  105. ##### Starts VDA Removal if it hasn't started
  106. if (`$gc -match "vda removal" -eq `$false) {
  107. "vda removal start "+(get-date).tostring() | Out-File `$log -Append
  108. ##### removes any previous vda cleanup logs
  109. if (test-path `$culog) {ri (split-path `$culog -parent) -recurse -force}
  110. `$p = Start-Process -FilePath C:\VDACleanupUtility.exe -ArgumentList "/silent" -passthru
  111. wait-process `$p.id
  112. break
  113. } else {
  114. ##### detects if the vda cleanup is continuing after reboot
  115. if (get-process vdacleanuputility -ea silentlycontinue) {
  116. "vda removal continue "+(get-date).ToString() | Out-File `$log -Append
  117. get-process vdacleanuputility -ea silentlycontinue | wait-process
  118.  
  119. }
  120. if ((gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce) -match "citrixvdacleanup") {
  121. break
  122. }
  123. ##### If the vda cleanup utility has finished the script will get to this point - it waits for the log to show that
  124. ##### the utility has attempted to upload usage info to citrix - indicating it has finished
  125. while ((gc `$culog -last 1) -notlike "*upload*") {start-sleep -s 1}
  126. `$dvd = (gwmi win32_logicaldisk | ?{`$_.volumename -like "XA*"} | select -expand deviceid)+"\"
  127. `$setup = Join-Path `$dvd "x64\XenDesktop Setup\XenDesktopVDASetup.exe"
  128. ##### Edit your delivery controller(s) - separate by space
  129. `$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``""
  130. "Install VDA "+(get-date).tostring() | out-file `$log -append
  131. Start-Process `$setup -ArgumentList `$installargs -Wait
  132. ##### Session Recording install (optional) remove comment brackets to enable the install.  Remember that MSMQ-HTTP is a
  133. ##### prerequisite.  Depending on which OS you are using there are different commands to install it.
  134. ##### Since I installed it on my master image before deploying the stand alone MCS VDAs I didn't add this in
  135. <#
  136. `$sesins = Join-Path `$dvd "x64\Session Recording\SessionRecordingAgentX64.msi"
  137. ##### Assuming all ports are default update the SESSIONRECORDINGSERVERNAME
  138. `$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"
  139. "Install Session Recording "+(get-date).tostring() | out-file `$log -append
  140. start-process `$sesins -argumentlist `$sesinsargs -wait
  141. #>
  142. ##### Ejects the DVD
  143. `$diskmaster = New-Object -ComObject imapi2.msftdiscmaster2
  144. `$diskrecorder = new-object -ComObject imapi2.msftdiscrecorder2
  145. `$diskrecorder.initializediscrecorder(`$diskmaster)
  146. `$diskrecorder.ejectmedia()
  147. ##### Cleanup and restart
  148. cleanup
  149. restart-computer -force
  150. }
  151.  
  152. "@
  153.  
  154. foreach ($computer in $computers) {
  155. $sel = $vms | ?{$computer -like "$_`*"}
  156. if ($sel -eq $null) {break}
  157. &$xe vm-cd-insert -s $master -u root -pw $pass cd-name="$cd" vm="$sel"
  158. ##### Creates the script files on the remote computer
  159. $script -replace "computername",$computer| Out-File "\\$computer\c`$\upgrade.ps1"
  160. $script1  -replace "computername",$computer| Out-File "\\$computer\c`$\upgradetmp.ps1"
  161. ##### Edit the source of the VDA Cleanup Utility
  162. cp \\server\share\VDACleanupUtility\VDACleanupUtility.exe \\$computer\c`$
  163. ##### You will receive an error on the first scheduled task install due to the date/time - disregard
  164. Invoke-Command -ComputerName $computer -ScriptBlock {
  165. & 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
  166. & schtasks /create /tn upgrade /tr "powershell.exe -executionpolicy unrestricted -file c:\upgrade.ps1" /sc ONLOGON /ru Administrator /rl highest
  167. & schtasks /run /tn kickoff
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement