@@ -139,13 +139,7 @@ function Set-TargetResource
139139 Set-AutoManagePaging - State Disable
140140 }
141141
142- $driveInfo = [System.IO.DriveInfo ] $Drive
143-
144- if (-not $driveInfo.IsReady )
145- {
146- New-InvalidOperationException `
147- - Message ($script :localizedData.DriveNotReadyError -f $driveInfo.Name )
148- }
142+ $driveInfo = Get-DriveInfo - Drive $Drive
149143
150144 $existingPageFileSetting = Get-PageFileSetting `
151145 - Drive $ ($driveInfo.Name.Substring (0 , 2 ))
@@ -179,13 +173,7 @@ function Set-TargetResource
179173 Set-AutoManagePaging - State Disable
180174 }
181175
182- $driveInfo = [System.IO.DriveInfo ] $Drive
183-
184- if (-not $driveInfo.IsReady )
185- {
186- New-InvalidOperationException `
187- - Message ($script :localizedData.DriveNotReadyError -f $driveInfo.Name )
188- }
176+ $driveInfo = Get-DriveInfo - Drive $Drive
189177
190178 $existingPageFileSetting = Get-PageFileSetting `
191179 - Drive $ ($driveInfo.Name.Substring (0 , 2 ))
@@ -217,13 +205,7 @@ function Set-TargetResource
217205 Set-AutoManagePaging - State Disable
218206 }
219207
220- $driveInfo = [System.IO.DriveInfo ] $Drive
221-
222- if (-not $driveInfo.IsReady )
223- {
224- New-InvalidOperationException `
225- - Message ($script :localizedData.DriveNotReadyError -f $driveInfo.Name )
226- }
208+ $driveInfo = Get-DriveInfo - Drive $Drive
227209
228210 $existingPageFileSetting = Get-PageFileSetting `
229211 - Drive $ ($driveInfo.Name.Substring (0 , 2 ))
@@ -491,4 +473,36 @@ function New-PageFile
491473 }
492474}
493475
476+ <#
477+ . SYNOPSIS
478+ Gets the Drive info object for a specified
479+ Drive. It will throw an exception if the drive
480+ is invalid or does not exist.
481+
482+ . PARAMETER Drive
483+ The letter of the drive to get the drive info
484+ for.
485+ #>
486+ function Get-DriveInfo
487+ {
488+ [CmdletBinding ()]
489+ [OutputType ([System.IO.DriveInfo ])]
490+ param
491+ (
492+ [Parameter (Mandatory = $true )]
493+ [System.String ]
494+ $Drive
495+ )
496+
497+ $driveInfo = [System.IO.DriveInfo ] $Drive
498+
499+ if (-not $driveInfo.IsReady )
500+ {
501+ New-InvalidOperationException `
502+ - Message ($script :localizedData.DriveNotReadyError -f $driveInfo.Name )
503+ }
504+
505+ return $driveInfo
506+ }
507+
494508Export-ModuleMember - Function *- TargetResource
0 commit comments