Public/Get-CAMOrganization.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
function Get-CAMOrganization
{
    <#
    .SYNOPSIS
        Function to retrieve Organization from the Cireson Asset Management
    .DESCRIPTION
        Function to retrieve Organization from the Cireson Asset Management
    .EXAMPLE
        Get-CamOrganization
    .EXAMPLE
        Get-CamOrganization -Displayname 'IT'
    .EXAMPLE
        Get-CamOrganization -ID '80e80889-86d1-4cee-b1e9-fcd265fa54a2'
    .EXAMPLE
        Get-CamOrganization -Filter "ID -eq 80e80889-86d1-4cee-b1e9-fcd265fa54a2"
    .NOTES
        Francois-Xavier Cat
        @Lazywinadm
        www.lazywinadmin.com
        github.com/lazywinadmin
    #>

    [CmdletBinding(DefaultParameterSetName = 'All')]
    PARAM (
        [Parameter(ParameterSetName = 'DisplayName')]
        [System.String]$DisplayName,
        
        [Parameter(ParameterSetName = 'ID')]
        $Id,
        
        [Parameter(ParameterSetName = 'Filter')]
        $Filter
    )
    BEGIN
    {
        if (-not (Get-Module -Name SMLets)) { Import-Module -Name SMLets -ErrorAction Stop }
        
        Write-Debug -Message "ParameterSetName: $($PSCmdlet.ParameterSetName)"
        Write-Debug -Message "Parameters: $($PSBoundParameters.Keys)"
    }
    PROCESS
    {
        TRY
        {
            $Splatting = @{
                class = get-scsmclass -name 'Cireson.AssetManagement.Organization'
            }
            
            IF ($PSBoundParameters['DisplayName']) { get-scsmobject -class @Splatting -Filter "DisplayName -like $DisplayName" }
            ELSEIF ($PSBoundParameters['ID']) { get-scsmobject -class @Splatting -Filter "Id -eq $ID" }
            ELSEIF ($PSBoundParameters['Filter']) { get-scsmobject -class @Splatting -Filter $Filter }
            ELSE { Get-SCSMObject @Splatting }
        }
        CATCH
        {
            Write-Error -Message "[PROCESS] An Error occured"
            $Error[0].Exception.Message
        }
    }
}