User Tools

Site Tools

Write-Host "Restart Service on single Server" -foreground "yellow"
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"
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
restart_service_incl._wildcard_on_remote_server.txt · Last modified: 2018/11/21 12:14 by