-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from PowerShell/dev
Merging release pull request
- Loading branch information
Showing
13 changed files
with
483 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DSCResource.Tests | ||
DSCResource.Tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<# | ||
.SYNOPSIS | ||
Retrieves the localized string data based on the machine's culture. | ||
Falls back to en-US strings if the machine's culture is not supported. | ||
.PARAMETER ResourceName | ||
The name of the resource as it appears before '.strings.psd1' of the localized string file. | ||
For example: | ||
xSQLServerEndpoint: MSFT_xSQLServerEndpoint | ||
xSQLServerConfiguration: MSFT_xSQLServerConfiguration | ||
xSQLServerRole: MSFT_xSQLServerRole | ||
#> | ||
function Get-LocalizedData | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[String] | ||
$ResourceName | ||
) | ||
|
||
$resourceDirectory = Join-Path -Path $PSScriptRoot -ChildPath $ResourceName | ||
$localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath $PSUICulture | ||
|
||
if (-not (Test-Path -Path $localizedStringFileLocation)) | ||
{ | ||
# Fallback to en-US | ||
$localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath 'en-US' | ||
} | ||
|
||
Import-LocalizedData ` | ||
-BindingVariable 'localizedData' ` | ||
-FileName "$ResourceName.strings.psd1" ` | ||
-BaseDirectory $localizedStringFileLocation | ||
|
||
return $localizedData | ||
} | ||
|
||
Export-ModuleMember -Function @( | ||
'Get-LocalizedData' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` | ||
-ChildPath 'CommonResourceHelper.psm1') | ||
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xPowerPlan' | ||
|
||
<# | ||
.SYNOPSIS | ||
Returns the current state of the power plan. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER Name | ||
Specifies the name of the power plan to assign to the node. | ||
.EXAMPLE | ||
Get-TargetResource -IsSingleInstance 'Yes' -Name 'High performance' | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
# This is best practice when writing a single-instance DSC resource. | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name | ||
) | ||
|
||
$arguments = @{ | ||
Name = 'root\cimv2\power' | ||
Class = 'Win32_PowerPlan' | ||
Filter = "ElementName = '$Name'" | ||
} | ||
|
||
try | ||
{ | ||
$plan = Get-CimInstance @arguments | ||
} | ||
catch | ||
{ | ||
throw ($script:localizedData.PowerPlanCIMError -f $($arguments.Class) ) | ||
} | ||
|
||
if ($plan) | ||
{ | ||
if ($plan.IsActive) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.PowerPlanIsActive -f $Name) | ||
$activePlanName = $Name | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message ($script:localizedData.PowerPlanIsNotActive -f $Name) | ||
$activePlanName = $null | ||
} | ||
} | ||
else | ||
{ | ||
throw ($script:localizedData.PowerPlanNotFound -f $Name) | ||
} | ||
|
||
return @{ | ||
IsSingleInstance = $IsSingleInstance | ||
Name = $activePlanName | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Assign the power plan to the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER Name | ||
Specifies the name of the power plan to assign to the node. | ||
.EXAMPLE | ||
Set-TargetResource -IsSingleInstance 'Yes' -Name 'High performance' | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
# This is best practice when writing a single-instance DSC resource. | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name | ||
) | ||
|
||
Write-Verbose -Message ($script:localizedData.PowerPlanIsBeingActivated -f $Name) | ||
|
||
$arguments = @{ | ||
Name = 'root\cimv2\power' | ||
Class = 'Win32_PowerPlan' | ||
Filter = "ElementName = '$Name'" | ||
} | ||
|
||
try | ||
{ | ||
$plan = Get-CimInstance @arguments | ||
} | ||
catch | ||
{ | ||
throw ($script:localizedData.PowerPlanCIMError -f $($arguments.Class) ) | ||
} | ||
|
||
try | ||
{ | ||
$plan | Invoke-CimMethod -MethodName Activate | ||
} | ||
catch | ||
{ | ||
throw ($script:localizedData.PowerPlanWasUnableToBeSet -f $Name, $($_.Exception.Message)) | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests if the power plan is assigned to the node. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER Name | ||
Specifies the name of the power plan to assign to the node. | ||
.EXAMPLE | ||
Test-TargetResource -IsSingleInstance 'Yes' -Name 'High performance' | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
# This is best practice when writing a single-instance DSC resource. | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name | ||
) | ||
|
||
$returnValue = $false | ||
|
||
Write-Verbose -Message ($script:localizedData.PowerPlanIsBeingValidated -f $Name) | ||
|
||
$getTargetResourceResult = Get-TargetResource -IsSingleInstance $IsSingleInstance -Name $Name | ||
if ($getTargetResourceResult.Name -eq $Name) | ||
{ | ||
$returnValue = $true | ||
} | ||
|
||
return $returnValue | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("xPowerPlan")] | ||
class MSFT_xPowerPlan : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; | ||
[Required, Description("The name of the power plan to activate.")] String Name; | ||
}; |
6 changes: 6 additions & 0 deletions
6
DSCResources/MSFT_xPowerPlan/en-US/MSFT_xPowerPlan.schema.mfl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Description("This resource is used to activate a power plan.") : Amended,AMENDMENT, LOCALE("MS_409")] | ||
class MSFT_xPowerPlan : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'") : Amended] String IsSingleInstance; | ||
[Description("The name of the power plan to activate.") : Amended] String Name; | ||
}; |
11 changes: 11 additions & 0 deletions
11
DSCResources/MSFT_xPowerPlan/en-US/MSFT_xPowerPlan.strings.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Localized resources for WindowsOptionalFeature | ||
|
||
ConvertFrom-StringData @' | ||
PowerPlanIsActive = The power plan '{0}' is the active plan. | ||
PowerPlanIsNotActive = The power plan '{0}' is not the active plan. | ||
PowerPlanNotFound = Unable to find the power plan '{0}'. | ||
PowerPlanIsBeingActivated = Activating power plan '{0}' | ||
PowerPlanIsBeingValidated = Validating power plan '{0}' | ||
PowerPlanWasUnableToBeSet = Unable to set the power plan '{0}' to the active plan. Error message: {1} | ||
PowerPlanCIMError = Could not get the Common Information Model (CIM) instances of class {0} | ||
'@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<# | ||
.SYNOPSIS | ||
Example to set a power plan. | ||
.DESCRIPTION | ||
This examples sets the active power plan to the 'High performance' plan. | ||
#> | ||
Configuration Sample_xPowerPlan | ||
{ | ||
param | ||
( | ||
[Parameter()] | ||
[String[]] | ||
$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName xComputerManagement | ||
|
||
Node $NodeName | ||
{ | ||
xPowerPlan SetPlanHighPerformance | ||
{ | ||
IsSingleInstance = 'Yes' | ||
Name = 'High performance' | ||
} | ||
} | ||
} | ||
|
||
Sample_xPowerPlan | ||
Start-DscConfiguration -Path Sample_xPowerPlan -Wait -Verbose -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,4 +130,4 @@ Configuration xScheduledTask_Disable | |
Ensure="Present" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.