Public/Get-CAMSupportContract.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function Get-CAMSupportContract
{
<#
    .SYNOPSIS
        Function to retrieve Support Contract from the Cireson Asset Management
     
    .DESCRIPTION
        Function to retrieve Support Contract from the Cireson Asset Management
     
    .PARAMETER DisplayName
        Specifies the DisplayName
     
    .PARAMETER ID
        Specifies the ID of the contract. Typically the GUID.
     
    .PARAMETER Filter
        Specifies the filter you want to apply
     
    .PARAMETER DaysLeft
        Specifies the days before expiration of the contract
 
    .EXAMPLE
        Get-CAMSupportContract
         
        Retrieve all the contract
     
    .EXAMPLE
        Get-CAMSupportContract -DisplayName "Dell*"
         
        Retrieve the contracts Display Name starting by Dell
     
    .EXAMPLE
        Get-CAMSupportContract -id '3cbgg558-a09c-b717-2401-05aef430b01f'
         
        Retrieve the specific Contract with the ID '3cbgg558-a09c-b717-2401-05aef430b01f'
     
    .EXAMPLE
        Get-CAMSupportContract -DaysLeft 30
         
        Retrieve contracts expiring in the next 30 days
     
    .EXAMPLE
        Get-CAMSupportContract -Expired
         
        Retrieve all the expired contracts
         
    .EXAMPLE
        Get-CAMSupportContract -Filter "Name -eq 'Google'"
         
        Retrieve Support contract with the name Google
     
    .NOTES
        Francois-Xavier Cat
        www.lazywinadmin.com
        @lazywinadm
        github.com/lazywinadmin
#>

    
    [CmdletBinding(DefaultParameterSetName = 'All')]
    param
    (
        [Parameter(ParameterSetName = 'DisplayName')]
        [System.String]$DisplayName,
        
        [Parameter(ParameterSetName = 'ID')]
        $Id,
        
        [Parameter(ParameterSetName = 'Filter')]
        [System.String]$Filter,
        
        [Parameter(ParameterSetName = 'ExpirationDays')]
        [Int]$DaysLeft
        
        <#[Parameter(ParameterSetName = 'Status')]
        #[ValidateSet('OK','Warning', 'Expired')]
        [Cireson.AssetManagement.ContractS]$Status,#>

    )
    
    BEGIN
    {
        
        if (-not (Get-Module -Name SMLets)) { Import-Module -Name SMLets -ErrorAction Stop }
        
        Write-Verbose "[BEGIN] ParameterSet: $($PSCmdlet.ParameterSetName)"
    }
    PROCESS
    {
        TRY
        {
            $Splatting = @{
                Class = (get-scsmclass -name 'Cireson.AssetManagement.SupportContract')
            }
            
            IF ($PSBoundParameters['DisplayName'])
            {
                $Splatting.Filter = "DisplayName -like $DisplayName"
            }
            ELSEIF ($PSBoundParameters['ID'])
            {
                $Splatting.Filter = "Id -eq $ID"
            }
            ELSEIF ($PSBoundParameters['Filter'])
            {
                $Splatting.Filter =  $Filter
            }
            ELSEIF ($PSBoundParameters['DaysLeft'])
            {
                $Splatting.Filter =  "ContractEndDate -lt $((Get-Date).AddDays($DaysLeft))" #-and ContractEndDate -ge $(Get-Date)"
            }
            
            Get-SCSMObject @Splatting
            
        }
        CATCH
        {
            Write-Error -Message "[PROCESS] An Error occured"
            $Error[0]
        }
    }
}