DSCResources/TAMZ_cPowerPlan/TAMZ_cPowerPlan.psm1
function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [System.String] $PlanName ) $ElementName = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "IsActive='True'").ElementName.tostring() $returnValue =@{ PlanName = $ElementName } $returnValue } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [System.String] $PlanName ) Write-Verbose -Message "Setting Powerplan to $PlanName" $guid = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "ElementName='$PlanName'").InstanceID.tostring() $regex = [regex]"{(.*?)}$" $newpowerVal = $regex.Match($guid).groups[1].value # setting power setting to high performance powercfg -S $newpowerVal } function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [System.String] $PlanName ) $ElementName = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "IsActive='True'").ElementName.tostring() If($ElementName -eq $PlanName) { Write-Verbose -Message "PowerPlan is set to $PlanName Already" return $true } else { Write-Verbose -Message "PowerPlan is $ElementName Expect $PlanName" return $false } } Export-ModuleMember -Function *-TargetResource |