Public/Get-CAMSoftwareAsset.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
function Get-CAMSoftwareAsset
{
    <#
    .SYNOPSIS
        Function to retrieve Software Asset from the Cireson Asset Management
    .DESCRIPTION
        Function to retrieve Software Asset from the Cireson Asset Management
    .EXAMPLE
        Get-CamSoftwareAsset
    .EXAMPLE
        Get-CamSoftwareAsset -DisplayName "*Pro"
    .EXAMPLE
        Get-CamSoftwareAsset -id '3cbgg558-a09c-b717-2401-05aef430b01f'
    .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,
        
        $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.SoftwareAsset')
            }
            
            IF ($PSBoundParameters['DisplayName']) { get-scsmobject @Splatting -Filter "DisplayName -like $DisplayName" }
            ELSEIF ($PSBoundParameters['ID']) { get-scsmobject @Splatting -Filter "Id -eq $ID" }
            ELSE { get-scsmobject @Splatting }
        }
        CATCH
        {
            Write-Error -Message "[PROCESS] An Error occured while querying Software Assets"
            $Error[0].Exception.Message
        }
    }
}