# Shutdown.ps1 # # V1 - 22/06/2011 # #(Auteur: Damien BENOIT) $Objet = "computer" $objDomaine = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=monOU,DC=monDomaine,DC=local") $objSearcher = New-Object System.DirectoryServices.DirectorySearcher($objDomaine,"(objectCategory=$Objet)",@('name')) $requete = $objSearcher.FindAll() | %{$_.properties.name} # Création du fichier de log Start-Transcript -path C:\shutdown.log Foreach($PC IN $requete) { # Test si l'ordinateur est allumé $pingresult = Get-WmiObject Win32_PingStatus -f "Address='$PC'" $StatusCode = $pingresult.statuscode # Si le statuscode = 0 alors l'ordinateur est allumé If($StatusCode -eq 0) { $IPcible = $pingresult.IPV4Address.IPAddressToString Write-Host -ForegroundColor Red -BackgroundColor Black "L'ordinateur $PC (IP: $IPcible) va s'éteindre...`r" # Exctinction de l'ordinateur (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $IPcible).Win32Shutdown(1) } Else { Write-host -ForegroundColor Green -BackgroundColor Black "L'ordinateur $PC est éteint.`r" } } # Arret du log Stop-Transcript