|
# DESCRIPTION ###########################################################################################
#########################################################################################################
# Script name: OSD.ps1
# Created on: 20/11/2012
# Author: Damien Cuvelier (Alsy)
# Purpose: Paramétrage des postes et déploiement des add-ons et applications liés au Master 7
# Le script interroge la valeur wmi du chassis et agit en conséquence
#
# History: - Damien Cuvelier 20/11/2012
# Script Creation.
# -
#########################################################################################################
#########################################################################################################
$ErrorActionPreference = "silentlycontinue"
$logfile = "c:\windows\temp\logpowerplan.log"
function Get-ScriptDirectory {
if (Test-Path variable:\hostinvocation)
{$FullPath=$hostinvocation.MyCommand.Path}
Else {
$FullPath=(get-variable myinvocation -scope script).value.Mycommand.Definition }
if (Test-Path $FullPath) {
return (Split-Path $FullPath)
}
Else {
$FullPath=(Get-Location).path
Write-Warning ("Get-ScriptDirectory: Powershell Host <" + $Host.name + "> may not be compatible with this function, the current directory <" + $FullPath +
"> will be used.")
return $FullPath
}
}
function scheme
{param ($Plan,$action)
Set-StrictMode -Version Latest
# List des plans.
$planList = powercfg.exe -l
# Récupération du GUID
$planRegEx = "(?<PlanGUID>[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}\-){3}[A-Fa-f0-9]{12})" + ("(?:\s+\({0}\))" -f $Plan)
# Si le plan apparait dans la liste...
if ( ($planList | Out-String) -match $planRegEx )
{
if ($action = "set")
{$result = powercfg -s $matches["PlanGUID"] 2>&1}
elseif ($action = "del")
{$result = powercfg -d $matches["PlanGUID"] 2>&1}
elseif ($action = "export")
{$result = powercfg -EXPORT c:\windows\temp\scheme.pow $matches["PlanGUID"] 2>&1}
if ( $LASTEXITCODE -ne 0)
{# on execute la commande
$result}
}
else
{# en cas d'erreur on log.
Write-Error ("The requested power scheme '{0}' does not exist on this machine" -f $Plan) | out-file -FilePath $logfile -Append}
}
## définir l'emplacement du script
##################################
$ScriptPath = Get-ScriptDirectory
Set-Location $ScriptPath
## Réactivation Mise en veille avec le scheme scheme.pow qui porte le nom Balanced
Write-Host "Réactivation Mise en veille" | out-file -FilePath $logfile -Append
POWERCFG -IMPORT c:\windows\temp\scheme.pow | out-file -FilePath $logfile -Append
scheme "Balanced" "set"
scheme "PowerConfigOSD" "del"
## Nettoyage du scheme default:
Remove-Item c:\windows\temp\scheme.pow | out-file -FilePath $logfile -Appen
|
Commenter cet article