update
This commit is contained in:
72
NRPE/Task-Restart-Service.ps1
Normal file
72
NRPE/Task-Restart-Service.ps1
Normal file
@ -0,0 +1,72 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
<Overview of script>
|
||||
|
||||
.NOTES
|
||||
Version : 1.0
|
||||
Author : Hubert CORNET
|
||||
Creation Date : <Date>
|
||||
Purpose/Change : <Initial script development>
|
||||
|
||||
.LINK
|
||||
https://www.tips-of-mine.fr
|
||||
|
||||
.EXEMPLE
|
||||
<Example goes here. Repeat this attribute for more than one example>
|
||||
|
||||
.DESCRIPTION
|
||||
<Brief description of script>
|
||||
|
||||
.PARAMETER <Parameter_Name>
|
||||
<Brief description of parameter input required. Repeat this attribute if required>
|
||||
|
||||
.INPUTS
|
||||
<Inputs if any, otherwise state None>
|
||||
|
||||
.OUTPUTS
|
||||
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
|
||||
#>
|
||||
|
||||
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$True,Position=1)]
|
||||
[int]$ServiceName
|
||||
)
|
||||
|
||||
# Définir l'action d'erreur pour continuer silencieusement
|
||||
$ErrorActionPreference = "SilentlyContinue"
|
||||
|
||||
#----------------------------------------------------------[Declarations]----------------------------------------------------------
|
||||
# Version Script
|
||||
$sScriptVersion = "1.0"
|
||||
|
||||
#Log File Info
|
||||
$sLogPath = "C:\Tmp"
|
||||
$sLogName = "Task-Restart-Service.log"
|
||||
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
|
||||
|
||||
Start-Transcript -Path $sLogFile -NoClobber
|
||||
|
||||
#-----------------------------------------------------------[Functions]------------------------------------------------------------
|
||||
|
||||
#------------------------------------------------------------[Script]--------------------------------------------------------------
|
||||
|
||||
Foreach ($Service in $ServiceName) {
|
||||
Restart-Service $ServiceName -ErrorAction SilentlyContinue -ErrorVariable ServiceError
|
||||
|
||||
If (!$ServiceError) {
|
||||
$Time=Get-Date
|
||||
Write-Host "Redémarrage du service $Service à $Time"
|
||||
}
|
||||
|
||||
If ($ServiceError) {
|
||||
write-host $error[0]
|
||||
exit 3
|
||||
}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
|
||||
|
||||
Stop-Transcript
|
Reference in New Issue
Block a user