Public/Get-CAMLocation.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-CAMLocation
{
    <#
    .SYNOPSIS
        Function to retrieve Location from the Cireson Asset Management
    .DESCRIPTION
        Function to retrieve Location from the Cireson Asset Management
    .EXAMPLE
        Get-CAMLocation
    .EXAMPLE
        Get-CAMLocation -DisplayName "*Pro"
    .EXAMPLE
        Get-CAMLocation -id '3cbgg558-a09c-b717-2401-05aef430b01f'
    .NOTES
        Francois-Xavier Cat
        @Lazywinadm
        www.lazywinadmin.com
        github.com/lazywinadmin
    #>

    [CmdletBinding(DefaultParameterSetName = 'DisplayName')]
    PARAM (
        [Parameter(ParameterSetName = 'DisplayName')]
        [System.String]$DisplayName,
        
        [Parameter(ParameterSetName = 'ID')]
        $Id
    )
    BEGIN
    {
        if (-not (Get-Module -Name SMLets)) { Import-Module -Name SMLets -ErrorAction Stop }
    }
    PROCESS
    {
        TRY
        {
            IF ($PSBoundParameters['DisplayName'])
            {
                Write-Verbose -Message "[PROCESS] Parameter: DisplayName"
                get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.Location') -Filter "DisplayName -like $DisplayName"
            }
            ELSEIF ($PSBoundParameters['ID'])
            {
                Write-Verbose -Message "[PROCESS] Parameter: ID"
                get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.Location') -Filter "Id -eq $ID"
            }
            ELSE
            {
                Write-Verbose -Message "[PROCESS] No Parameter specified, retrieving all"
                get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.Location')
            }
        }
        CATCH
        {
            Write-Error -Message "[PROCESS] An Error occured while querying Hardware Assets"
            $Error[0].Exception.Message
        }
    }
}