Bonjour,
J'ai un script pour éteindre mes postes a une heure via une tache planifié mais je n'ai aucun log pour voir si mes poste sont éteint ou pas donc je fait appel a vous pour m'aider. J'ai commencer déja a faire remplir un fichier .txt mais il me manque la date et la fin de l’exécution du script.
Voici le code pour éteindre mes postes :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| set-variable -name repDeBase -value "C:\Shutdown"
Import-Module $repDeBase\File.ps1
function Stop-computers
{
<#
.SYNOPSIS
These commands force an immediate shut down of all of the computers in a text file
.PARAMETER file
The file with all computers names
.EXAMPLE
Stop-Computers computers.txt
#>
param(
[Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)]
[string]$file,
[string]$JournalFile="$repDeBase\Journal.txt"
)
#On ouvre le fichier csv qui contient le nom des ordinateurs à arrêter
$csv = import-csv -path $file -OutVariable string
#The third command shuts down the computers.
#It uses ComputerName parameter to submit the list of computers in the $s variable, the Force parameter to force an immediate shutdown, and the Credential parameter to submit the credentials saved in the $c variable. It also uses the ThrottleLimit parameter to limit the command to 10 concurrent connections.
foreach ($Mem in $csv)
{
$c = $Mem.computers
if (Test-Connection -computername $Mem.computers -quiet) {
stop-computer -computername $Mem.computers -force -throttlelimit 10
write-output "'$c est éteint"
add-content -path $journalFile -value "L'ordinateur $c est éteint"
} else {
write-output "'$c ne repond pas au ping"
add-content -path $journalFile -value "L'ordinateur $c ne repond pas au ping"
}
}
}
stop-computers $repDeBase\PostesProfs.csv
#http://souriceau.com/pages/message_d_erreur_le_service_rpc_n_est_pas_disponible_pag.html |
Et mon fichier pour le début et la fin du script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| function open-file {
param(
[Parameter(Mandatory=$false,Position=1,ValueFromPipeline=$false)]
[string]$path
)
add-content -path $path -value ""
add-content -path $path -value ""
add-content -path $path -value ""
add-content -path $path -value "###############################################################################################################"
$d = Get-Date
add-content -path $path -value "Début du script pour allumer les postes profs du collège : $d"
add-content -path $path -value "###############################################################################################################"
add-content -path $path -value ""
}
function close-file {
param(
[Parameter(Mandatory=$false,Position=1,ValueFromPipeline=$false)]
[string]$path
)
add-content -path $path -value ""
add-content -path $JournalFile -value "###############################################################################################################"
$d = Get-Date
add-content -path $JournalFile -value "Fin du script pour allumer les postes profs du collège : $d"
add-content -path $JournalFile -value "###############################################################################################################"
} |
Pour l'instant dans fichier Journal.txt, j'ai juste
L'ordinateur AS2-CLIENT01 est éteint
Merci de votre aide
Partager