87 lines
2.5 KiB
PowerShell
87 lines
2.5 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Lorsque l'on doit modifier un ou plusieur fichier sur des serveurs de facon rapide et relancer le service associé à l'application
|
|
|
|
.NOTES
|
|
Version: 1.0
|
|
Author: Hubert CORNET
|
|
Creation Date: 15/11/2022
|
|
Purpose/Change:
|
|
|
|
.LINK
|
|
https://www.tips-of-mine.fr
|
|
|
|
.EXEMPLE
|
|
|
|
|
|
.DESCRIPTION
|
|
Permet de modifier le contenu d'un fichier et relancer le service assosié
|
|
|
|
.PARAMETER <Parameter_Name>
|
|
|
|
|
|
.INPUTS
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
#>
|
|
|
|
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
|
|
|
|
# Définir l'action d'erreur pour continuer silencieusement
|
|
$ErrorActionPreference = "SilentlyContinue"
|
|
|
|
# Bibliothèques de fonctions requises
|
|
|
|
#----------------------------------------------------------[Declarations]----------------------------------------------------------
|
|
# Version Script
|
|
$sScriptVersion = "1.0"
|
|
|
|
#Log File Info
|
|
$sLogPath = "C:\Tmp"
|
|
$sLogName = "<script_name>.log"
|
|
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
|
|
|
|
#-----------------------------------------------------------[Functions]------------------------------------------------------------
|
|
|
|
#------------------------------------------------------------[Script]--------------------------------------------------------------
|
|
|
|
cls
|
|
|
|
# Liste l'ensemble des serveurs d'un domaine
|
|
$ListServer = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'}
|
|
|
|
Foreach ($ServerName in $ListServer) {
|
|
Try {
|
|
Test-Connection -computername $ServerName.DNSHostName -Count 1 -ErrorAction stop | Out-Null
|
|
|
|
Write-host $ServerName.DNSHostName
|
|
|
|
$ServerFolder = Invoke-Command -ComputerName $ServerName.DNSHostName -ScriptBlock{
|
|
$FileToCheck = "C:\Program Files\CYBERWATCH SAS\CyberwatchAgent\agent.conf"
|
|
|
|
If (Test-Path $FileToCheck -PathType leaf) {
|
|
Write-host " - Fichier present"
|
|
|
|
# Ouvre le fichier
|
|
$content = Get-Content $FileToCheck
|
|
|
|
# Modifie la ligne 12
|
|
$content[11] = "enabled = True"
|
|
|
|
# Sauvegarde le fichier
|
|
$content | Set-Content -Path $FileToCheck
|
|
|
|
# relance le service
|
|
Restart-Service -Name CyberwatchService
|
|
}
|
|
Else {
|
|
Write-host " - pas de fichier"
|
|
}
|
|
}
|
|
}
|
|
Catch [System.Net.NetworkInformation.PingException] {
|
|
Write-Warning "$ServerName ne répond pas"
|
|
}
|
|
} |