japmtg

Update Java on a Windows 2008 R2 terminal server farm

Mar 22nd, 2013
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #wip_java_update.ps1
  2. #Java installer/updater
  3. #Prerequisites PS 2.0 and http://archive.msdn.microsoft.com/PSTerminalServices. Only tested on 2008 R2.
  4. #
  5. #Setup - Change these to meet your needs
  6. Import-Module PSTerminalServices
  7. $Serverlist = new-pssession -computername ts01,ts02,ts03
  8. $Message = "The server is going down for maintenance in 10 minutes. Please save your work and logoff."
  9. $MailServer = smtp.mail.com
  10. $MailSender = scripts@mail.com
  11. $MailRecipient = admin@email.com
  12. #
  13. #Begin Install/Update
  14. #Change logon mode to drain.
  15. invoke-command -session $serverlist -scriptblock {change logon /drain}
  16. #Send warning to all users
  17. get-content x:\scripts\servers.txt | foreach {Get-TSSession -State Active -ComputerName $_ | Send- SMessage $Message}
  18. #Wait X minutes
  19. Start-Sleep -seconds 600
  20. #Force all users to log off
  21. get-content x:\scripts\servers.txt | foreach {{Get-TSSession -ComputerName $_ -Username [a-z]** | Stop-TSSession –Force}
  22. #Copy installation application to temp folder on all servers
  23. get-content x:\scripts\servers.txt | foreach {Copy-Item x:\jre.exe -Destination \\$_\c$\temp}
  24. #change server mode to install
  25. invoke-command -session $Serverlist -scriptblock {change user /install}
  26. #Execute installer
  27. invoke-command -session $Serverlist -scriptblock {c:\temp\jre.exe /s IEXPLORER=1 /L C:\setup.log}
  28. #Wait X minutes. Need to add process query and resume when all installs are finished
  29. Start-Sleep -seconds 360
  30. #Change user mode to execute
  31. invoke-command -session $serverlist -scriptblock {change user /execute}
  32. #Change logon mode to enabled so that users can log back in
  33. invoke-command -session $serverlist -scriptblock {change logon /enable}
  34. #Set SMTP server
  35. $smtp = New-Object Net.Mail.SmtpClient("$MailServer")
  36. #Send completion email
  37. $smtp.Send("$MailSender","$MailRecepient","Java Update Completed","Java installed!")
  38. #Close all remote sessions created in this script
  39. remove-pssession -session $Serverlist
Advertisement
Add Comment
Please, Sign In to add comment