Public/Volume.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 <#
.SYNOPSIS
    Test the volume specified
.DESCRIPTION
    Can be specified to target a specific volume for testing
.PARAMETER Target
    Specifies the drive letter or file system label of the volume to test
.PARAMETER Property
    Specifies an optional property to test for on the volume
.PARAMETER Should
    A Script Block defining a Pester Assertion.
.EXAMPLE
 Volume C HealthStatus { Should be 'Healthy' }
.EXAMPLE
 Volume C FileSystem { Should be 'NTFS' }
 .EXAMPLE
 Volume D AllocationUnitSize { Should be 64K }
.EXAMPLE
 Volume MyFileSystemLabel SizeRemaining { Should BeGreaterThan 1GB }
.NOTES
    Assertions: Be
#>
  
  
function Volume {
    [CmdletBinding(DefaultParameterSetName="Default")]
    param(
        [Parameter(Mandatory, Position=1,ParameterSetName="Default")]
        [Parameter(Mandatory, Position=1,ParameterSetName="Property")]
        [Alias('Name')]
        [string]$Target,
        
        [Parameter(Position=2,ParameterSetName="Property")]
        [ValidateSet('AllocationUnitSize', 'DedupMode', 'DriveLetter', 'DriveType', 'FileSystem', 'FileSystemLabel',
                     'FileSystemType', 'HealthStatus', 'ObjectId', 'OperationalStatus', 'Path', 'Size', 'SizeRemaining')]
        [string]$Property,

        [Parameter(Mandatory, Position=2,ParameterSetName="Default")]
        [Parameter(Mandatory, Position=3,ParameterSetName="Property")]
        [scriptblock]$Should
    )

    function GetVolume([string]$Name) {
        if ($Name.Length -eq 1) {
            $v = Get-Volume -DriveLetter $Name -ErrorAction SilentlyContinue
            if (-not $v) {
                $v = Get-Volume -FileSystemLabel $Name  -ErrorAction SilentlyContinue    
            }
        } else {
            $v = Get-Volume -FileSystemLabel $Name  -ErrorAction SilentlyContinue
        }
        $v
    }
    
    $expression = { GetVolume -Name '$Target' }
                 
    $params = Get-PoshspecParam -TestName Volume -TestExpression $expression @PSBoundParameters
    
    Invoke-PoshspecExpression @params
}