Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Restarts Docs Content Manager services
- .EXAMPLE
- Restart-Docs
- Restart-Docs -WindowsServices
- Restart-Docs -ComponentServices
- Restart-Docs -ApplicationPools
- Restart-Docs -ComponentServices -ApplicationPools
- .NOTES
- Author: Jan Horsman
- #>
- #Requires -RunAsAdministrator
- [CmdletBinding()]
- Param(
- [parameter(Mandatory=$false, HelpMessage="Restart Windows services")]
- [switch]$WindowsServices,
- [parameter(Mandatory=$false, HelpMessage="Restart component services")]
- [switch]$ComponentServices,
- [parameter(Mandatory=$false, HelpMessage="Restart IIS application pools")]
- [switch]$ApplicationPools)
- $ErrorActionPreference = "Stop"
- if($WindowsServices -ne $true -and $ComponentServices -ne $true -and $ApplicationPools -ne $true)
- {
- #default to restarting everything
- $WindowsServices = $true
- $ComponentServices = $true
- $ApplicationPools = $true
- }
- if($WindowsServices)
- {
- Write-Host "Restarting Trisoft services"
- $services = Get-Service | Where { $_.DisplayName.StartsWith("Trisoft") }
- if($services -eq $null)
- {
- Write-Warning "Could not find Trisoft services"
- } else
- {
- foreach ($svc in $services)
- {
- if($svc.Status -eq "Running")
- {
- Write-Host (" restarting {0} " -f $svc.DisplayName)
- Restart-Service $svc.name -Force
- } else {
- Write-Host (" ignoring {0}, it is {1}" -f $svc.DisplayName, $svc.Status)
- }
- }
- }
- }
- if($ComponentServices)
- {
- Write-Host "Restarting component services"
- $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
- $apps = $comAdmin.GetCollection("Applications")
- $apps.Populate();
- # restart only Trisoft-InfoShare-Author because the other component services are libraries
- $apps = $apps | Where-Object { $_.Name.Equals("Trisoft-InfoShare-Author") }
- if($apps -eq $null)
- {
- Write-Warning "Could not find Trisoft-InfoShare-Author component service"
- } else
- {
- foreach ($app in $apps)
- {
- $comAdmin.ShutdownApplication($app.Name)
- Write-Host " Stoped " $app.Name
- $comAdmin.StartApplication($app.Name)
- Write-Host " Started" $app.Name
- }
- }
- }
- if($ApplicationPools)
- {
- Write-Host "Restarting application pools"
- Import-Module "IISAdministration"
- $appPools = Get-IISAppPool | Where-Object { $_.Name.StartsWith("Trisoft") }
- if($appPools -eq $null) {
- Write-Warning "Could not find Trisoft app pools"
- } else
- {
- foreach ($pool in $appPools)
- {
- if($pool.State -ne "Started")
- {
- Write-Host " ignoring "$pool.Name", it is"$pool.Status
- } else {
- $result = $pool.Recycle()
- Restart-WebAppPool $pool.Name
- if($result -eq "Started")
- {
- Write-Host " Recycled " $pool.Name
- } else
- {
- Write-Warning ("Unexpected result while recycling app pool {0}: {1}" -f $pool.Name, $result)
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment