Functions/Test-IsNull.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
60
61
62
63
64
65
66
67
68
69
70
71
72
function Test-IsNull {
<#
.SYNOPSIS
    Given a passed [string] tests to determine if .IsNullOrEmpty() or .IsNullOrWhitespace(), with .IsNullOrEmpty() being the default
.DESCRIPTION
    Given a passed [string] tests to determine if .IsNullOrEmpty() or .IsNullOrWhitespace(), with .IsNullOrEmpty() being the default
.PARAMETER String
    A [string] that you wanted tested to see if Null or (Empty or WhiteSpace). In both parameter set names 'Empty' and 'WhiteSpace'
.PARAMETER Empty
    A switch to control if looking for .IsNullOrEmpty()
.PARAMETER WhiteSpace
    A switch to control if looking for .IsNullOrWhitespace()
.EXAMPLE
    Test-IsNull -String ''
 
    Would return
    $true
.EXAMPLE
    Test-IsNull -String ' '
 
    Would return
    $false
.EXAMPLE
    Test-IsNull -String " `t " -WhiteSpace
 
    Would return
    $true
.OUTPUTS
    'bool'
#>


    [CmdletBinding(DefaultParameterSetName = 'Empty', ConfirmImpact = 'Low')]
    [OutputType('bool')]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter','')]
    Param
    (

        [Parameter(Position=0,ParameterSetName = 'Empty')]
        [Parameter(Position=0,ParameterSetName = 'WhiteSpace')]
        [string] $String,

        [Parameter(ParameterSetName = 'Empty')]
        [switch] $Empty,

        [Parameter(ParameterSetName = 'WhiteSpace')]
        [switch] $WhiteSpace

    )
    #endregion parameter

    begin {
        Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
        Write-Verbose -Message "ParameterSetName [$($PsCmdlet.ParameterSetName)]"
    }

    process {
        switch ($PsCmdlet.ParameterSetName) {
            'Empty' {
                $ReturnVal = [string]::IsNullOrEmpty($String)
            }
            'WhiteSpace' {
                $ReturnVal = [string]::IsNullOrWhitespace($String)
            }
        }
    }

    end {
        Write-Output -InputObject $ReturnVal
        Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
    }
}