Site Tools


restart_service_incl._wildcard_on_remote_server
restart_service.ps1
Write-Host 
Write-Host "Restart Service on single Server" -foreground "yellow"
Write-Host
 
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$ScriptPath = Get-ScriptDirectory
 
#Write-Host "Press any key to continue ..." -foreground "yellow"
 
#$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
 
$cmdlet = "ActiveDirectory" 
if ( (get-command -Name $cmdlet -ErrorAction SilentlyContinue) -eq $null ) {Import-module ActiveDirectory} 
 
$ExecUser = ([Environment]::UserName) 
 
$ServiceName = Read-Host "ServiceName or Part of Service Name to be started (Attention: Wildcard allowed, be carefull!"
$ServerName = Read-Host "ServerName"
 
Get-Service -ComputerName $ServerName -DisplayName "*$ServiceName*"
 
Write-Host "Search for Service" -foreground "yellow"
 
Write-Host "Stop Service $ServiceName on $ServerName" -foreground "yellow"
Get-Service -ComputerName $ServerName -DisplayName "*$ServiceName*" | Stop-Service -Force
Write-Host "Search for Service $ServiceName on $ServerName and show Status" -foreground "yellow"
Get-Service -DisplayName "*$ServiceName*" -ComputerName $ServerName
			ping FJTS1002 > $Null
Write-Host "Start Service $ServiceName on $ServerName" -foreground "yellow"
Get-Service -ComputerName $ServerName -DisplayName "*$ServiceName*" | Select-Object -Property * | foreach {set-service -ComputerName $ServerName -Name $_.Name -Status Running}
Write-Host "Search for Service $ServiceName on $ServerName and show Status" -foreground "yellow"
Get-Service -DisplayName "*$ServiceName*" -ComputerName $ServerName
 
Write-Host "Done! Services restart finished!" -foreground "yellow"
restart_service_incl._wildcard_on_remote_server.txt · Last modified: 2018/11/21 12:14 by 31.3.144.19