You can come across with two errors: SharePoint 2013 service pack 1 the installation of this package failed and Installation of SharePoint 2013 Cumulative Update takes 5 hours.

To overcome either of the above issue, follow the steps:
  1. Copy and save the below code with extension .ps1.

  2. In the same location, copy the cumulative updates or SP 1. Make sure there is only one exe file or cumulative updates in that specific location.

  3. Open the SharePoint Management Shell, run the file (.ps1):
  1. ##Ensure Patch is Present##
  2. $patchfile = Get - ChildItem | where {
  3. $_.Extension - eq“.exe”
  4. }
  5. if ($patchfile - eq $null) {
  6. Write - Host“Unable to retrieve the file.Exiting Script” - ForegroundColor Red
  7. Return
  8. }
  9. ##Stop Search Services##
  10. ##Checking Search services##
  11. $srchctr = 1
  12. $srch4srvctr = 1
  13. $srch5srvctr = 1
  14. $srv4 = get - service“OSearch15″
  15. $srv5 = get - service“SPSearchHostController”
  16. If(($srv4.status - eq“Running”) - or($srv5.status - eq“Running”)) {
  17. Write - Host“Choose 1 to Pause Search Service Application” - ForegroundColor Cyan
  18. Write - Host“Choose 2 to leave Search Service Application running” - ForegroundColor Cyan
  19. $searchappresult = Read - Host“Press 1 or 2 and hit enter”
  20. Write - Host
  21. if ($searchappresult - eq 1) {
  22. $srchctr = 2
  23. Write - Host“Pausing the Search Service Application” - foregroundcolor yellow
  24. Write - Host“This could take a few minutes” - ForegroundColor Yellow
  25. $ssa = get - spenterprisesearchserviceapplication
  26. $ssa.pause()
  27. }
  28. elseif($searchappresult - eq 2) {
  29. Write - Host“Continuing without pausing the Search Service Application”
  30. } else {
  31. Write - Host“Run the script again and choose option 1 or 2″ - ForegroundColor Red
  32. Write - Host“Exiting Script” - ForegroundColor Red
  33. Return
  34. }
  35. }
  36. Write - Host“Stopping Search Services
  37. if they are running” - foregroundcolor yellow
  38. if ($srv4.status - eq“Running”) {
  39. $srch4srvctr = 2
  40. set - service - Name“OSearch15″ - startuptype Disabled
  41. $srv4.stop()
  42. }
  43. if ($srv5.status - eq“Running”) {
  44. $srch5srvctr = 2
  45. Set - service“SPSearchHostController” - startuptype Disabled
  46. $srv5.stop()
  47. }
  48. do {
  49. $srv6 = get - service“SPSearchHostController”
  50. if ($srv6.status - eq“Stopped”) {
  51. $yes = 1
  52. }
  53. Start - Sleep - seconds 10
  54. }
  55. until ($yes - eq 1)
  56. Write - Host“Search Services are stopped” - foregroundcolor Green
  57. Write - Host#########################Stop Other Services#########################
  58. Set - Service - Name“IISADMIN” - startuptype Disabled
  59. Set - Service - Name“SPTimerV4″ - startuptype Disabled
  60. Write - Host“Gracefully stopping IIS W3WP Processes” - foregroundcolor yellow
  61. Write - Host
  62. iisreset - stop - noforce
  63. Write - Host“Stopping Services” - foregroundcolor yellow
  64. Write - Host
  65. $srv2 = get - service“SPTimerV4″
  66. if ($srv2.status - eq“Running”) {
  67. $srv2.stop()
  68. }
  69. Write - Host“Services are Stopped” - ForegroundColor Green
  70. Write - Host
  71. Write - Host####################Start patching####################
  72. Write - Host“Patching now keep this PowerShell window open” - ForegroundColor Magenta
  73. Write - Host
  74. $starttime = Get - Date
  75. $filename = $patchfile.basename
  76. $arg = “ / passive”
  77. Start - Process $filename $arg
  78. Start - Sleep - seconds 20
  79. $proc = get - process $filename
  80. $proc.WaitForExit()
  81. $finishtime = get - date
  82. Write - Host
  83. Write - Host“Patch installation complete” - foregroundcolor green
  84. Write - Host####################Start Services####################
  85. Write - Host“Starting Services Backup” - foregroundcolor yellow
  86. Set - Service - Name“SPTimerV4″ - startuptype Automatic
  87. Set - Service - Name“IISADMIN” - startuptype Automatic##Grabbing local server and starting services##
  88. $servername = hostname
  89. $server = get - spserver $servername
  90. $srv2 = get - service“SPTimerV4″
  91. $srv2.start()
  92. $srv3 = get - service“IISADMIN”
  93. $srv3.start()
  94. $srv4 = get - service“OSearch15″
  95. $srv5 = get - service“SPSearchHostController”###Ensuring Search Services were stopped by script before Starting”
  96. if ($srch4srvctr - eq 2) {
  97. set - service - Name“OSearch15″ - startuptype Automatic
  98. $srv4.start()
  99. }
  100. if ($srch5srvctr - eq 2) {
  101. Set - service“SPSearchHostController” - startuptype Automatic
  102. $srv5.start()
  103. }###Resuming Search Service Application
  104. if paused###
  105. if ($srchctr - eq 2) {
  106. Write - Host“Resuming the Search Service Application” - foregroundcolor yellow
  107. $ssa = get - spenterprisesearchserviceapplication
  108. $ssa.resume()
  109. }
  110. Write - Host“Services are Started” - foregroundcolor green
  111. Write - Host
  112. Write - Host
  113. Write - Host“Script Duration” - foregroundcolor yellow
  114. Write - Host“Started: ”$starttime - foregroundcolor yellow
  115. Write - Host“Finished: ”$finishtime - foregroundcolor yellow
  116. Write - Host“Script Complete”