1- Import-Module - Name (Join-Path - Path (Split-Path - Path $PSScriptRoot - Parent) `
2- - ChildPath ' CommonResourceHelper.psm1' )
3- $script :localizedData = Get-LocalizedData - ResourceName ' MSFT_xPowerPlan'
1+ $modulePath = Join-Path - Path (Split-Path - Path (Split-Path - Path $PSScriptRoot - Parent) - Parent) - ChildPath ' Modules'
2+
3+ # Import the ComputerManagementDsc Common Modules
4+ Import-Module - Name (Join-Path - Path $modulePath `
5+ - ChildPath (Join-Path - Path ' ComputerManagementDsc.Common' `
6+ - ChildPath ' ComputerManagementDsc.Common.psm1' ))
7+
8+ # Import the ComputerManagementDsc Resource Helper Module
9+ Import-Module - Name (Join-Path - Path $modulePath `
10+ - ChildPath (Join-Path - Path ' ComputerManagementDsc.ResourceHelper' `
11+ - ChildPath ' ComputerManagementDsc.ResourceHelper.psm1' ))
12+
13+ # Import Localization Strings
14+ $script :localizedData = Get-LocalizedData `
15+ - ResourceName ' MSFT_xPowerPlan' `
16+ - ResourcePath (Split-Path - Parent $Script :MyInvocation.MyCommand.Path )
417
518<#
619 . SYNOPSIS
@@ -33,19 +46,20 @@ function Get-TargetResource
3346 $Name
3447 )
3548
36- $arguments = @ {
37- Name = ' root\cimv2\power'
38- Class = ' Win32_PowerPlan'
49+ $getCimInstanceArguments = @ {
50+ Name = ' root\cimv2\power'
51+ Class = ' Win32_PowerPlan'
3952 Filter = " ElementName = '$Name '"
4053 }
4154
4255 try
4356 {
44- $plan = Get-CimInstance @arguments
57+ $plan = Get-CimInstance @getCimInstanceArguments
4558 }
4659 catch
4760 {
48- throw ($script :localizedData.PowerPlanCIMError -f $ ($arguments.Class ) )
61+ New-InvalidOperationException `
62+ - Message ($script :localizedData.PowerPlanCimError -f $getCimInstanceArguments.Class )
4963 }
5064
5165 if ($plan )
@@ -63,12 +77,13 @@ function Get-TargetResource
6377 }
6478 else
6579 {
66- throw ($script :localizedData.PowerPlanNotFound -f $Name )
80+ New-InvalidOperationException `
81+ - Message ($script :localizedData.PowerPlanNotFound -f $Name )
6782 }
6883
6984 return @ {
7085 IsSingleInstance = $IsSingleInstance
71- Name = $activePlanName
86+ Name = $activePlanName
7287 }
7388}
7489
@@ -104,19 +119,20 @@ function Set-TargetResource
104119
105120 Write-Verbose - Message ($script :localizedData.PowerPlanIsBeingActivated -f $Name )
106121
107- $arguments = @ {
108- Name = ' root\cimv2\power'
109- Class = ' Win32_PowerPlan'
122+ $getCimInstanceArguments = @ {
123+ Name = ' root\cimv2\power'
124+ Class = ' Win32_PowerPlan'
110125 Filter = " ElementName = '$Name '"
111126 }
112127
113128 try
114129 {
115- $plan = Get-CimInstance @arguments
130+ $plan = Get-CimInstance @getCimInstanceArguments
116131 }
117132 catch
118133 {
119- throw ($script :localizedData.PowerPlanCIMError -f $ ($arguments.Class ) )
134+ New-InvalidOperationException `
135+ - Message ($script :localizedData.PowerPlanCimError -f $getCimInstanceArguments.Class )
120136 }
121137
122138 try
@@ -125,7 +141,8 @@ function Set-TargetResource
125141 }
126142 catch
127143 {
128- throw ($script :localizedData.PowerPlanWasUnableToBeSet -f $Name , $ ($_.Exception.Message ))
144+ New-InvalidOperationException `
145+ - Message ($script :localizedData.PowerPlanWasUnableToBeSet -f $Name , $_.Exception.Message )
129146 }
130147}
131148
@@ -165,6 +182,7 @@ function Test-TargetResource
165182 Write-Verbose - Message ($script :localizedData.PowerPlanIsBeingValidated -f $Name )
166183
167184 $getTargetResourceResult = Get-TargetResource - IsSingleInstance $IsSingleInstance - Name $Name
185+
168186 if ($getTargetResourceResult.Name -eq $Name )
169187 {
170188 $returnValue = $true
0 commit comments