Guest User

Untitled

a guest
Dec 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. Restarts Docs Content Manager services
  4.  
  5. .EXAMPLE
  6. Restart-Docs
  7. Restart-Docs -WindowsServices
  8. Restart-Docs -ComponentServices
  9. Restart-Docs -ApplicationPools
  10. Restart-Docs -ComponentServices -ApplicationPools
  11.  
  12. .NOTES
  13. Author: Jan Horsman
  14. #>
  15.  
  16. #Requires -RunAsAdministrator
  17.  
  18. [CmdletBinding()]
  19. Param(
  20. [parameter(Mandatory=$false, HelpMessage="Restart Windows services")]
  21. [switch]$WindowsServices,
  22. [parameter(Mandatory=$false, HelpMessage="Restart component services")]
  23. [switch]$ComponentServices,
  24. [parameter(Mandatory=$false, HelpMessage="Restart IIS application pools")]
  25. [switch]$ApplicationPools)
  26.  
  27. $ErrorActionPreference = "Stop"
  28.  
  29. if($WindowsServices -ne $true -and $ComponentServices -ne $true -and $ApplicationPools -ne $true)
  30. {
  31. #default to restarting everything
  32. $WindowsServices = $true
  33. $ComponentServices = $true
  34. $ApplicationPools = $true
  35. }
  36.  
  37. if($WindowsServices)
  38. {
  39. Write-Host "Restarting Trisoft services"
  40. $services = Get-Service | Where { $_.DisplayName.StartsWith("Trisoft") }
  41.  
  42. if($services -eq $null)
  43. {
  44. Write-Warning "Could not find Trisoft services"
  45. } else
  46. {
  47. foreach ($svc in $services)
  48. {
  49. if($svc.Status -eq "Running")
  50. {
  51. Write-Host (" restarting {0} " -f $svc.DisplayName)
  52. Restart-Service $svc.name -Force
  53. } else {
  54. Write-Host (" ignoring {0}, it is {1}" -f $svc.DisplayName, $svc.Status)
  55. }
  56. }
  57. }
  58. }
  59.  
  60. if($ComponentServices)
  61. {
  62. Write-Host "Restarting component services"
  63. $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
  64. $apps = $comAdmin.GetCollection("Applications")
  65. $apps.Populate();
  66. # restart only Trisoft-InfoShare-Author because the other component services are libraries
  67. $apps = $apps | Where-Object { $_.Name.Equals("Trisoft-InfoShare-Author") }
  68. if($apps -eq $null)
  69. {
  70. Write-Warning "Could not find Trisoft-InfoShare-Author component service"
  71. } else
  72. {
  73. foreach ($app in $apps)
  74. {
  75. $comAdmin.ShutdownApplication($app.Name)
  76. Write-Host " Stoped " $app.Name
  77. $comAdmin.StartApplication($app.Name)
  78. Write-Host " Started" $app.Name
  79. }
  80. }
  81. }
  82.  
  83. if($ApplicationPools)
  84. {
  85. Write-Host "Restarting application pools"
  86. Import-Module "IISAdministration"
  87. $appPools = Get-IISAppPool | Where-Object { $_.Name.StartsWith("Trisoft") }
  88. if($appPools -eq $null) {
  89. Write-Warning "Could not find Trisoft app pools"
  90. } else
  91. {
  92. foreach ($pool in $appPools)
  93. {
  94. if($pool.State -ne "Started")
  95. {
  96. Write-Host " ignoring "$pool.Name", it is"$pool.Status
  97. } else {
  98. $result = $pool.Recycle()
  99. Restart-WebAppPool $pool.Name
  100. if($result -eq "Started")
  101. {
  102. Write-Host " Recycled " $pool.Name
  103. } else
  104. {
  105. Write-Warning ("Unexpected result while recycling app pool {0}: {1}" -f $pool.Name, $result)
  106. }
  107. }
  108. }
  109. }
  110. }
Add Comment
Please, Sign In to add comment