Functions/BusinessLayer/ESet.ps1

function Get-OIMESet {
    <#
    .SYNOPSIS
    Gets one or more ESet (entitlement set) objects.

    .EXAMPLE
    Get-OIMESet -Ident_ESet 'VPN Access'

    .EXAMPLE
    Get-OIMESet -id $uid
    #>

    [CmdletBinding(DefaultParameterSetName = 'Search')]
    param(
        [Parameter(ParameterSetName = 'Single', Mandatory = $true)]
        [Alias('uid')]
        [string]$id,

        [Parameter(ParameterSetName = 'Search')]
        [Alias('Name')]
        [string]$Ident_ESet,

        [Parameter(ParameterSetName = 'Search')]
        [string]$Where,

        [Parameter(ParameterSetName = 'Search')]
        [int]$First
    )

    if ($PSCmdlet.ParameterSetName -eq 'Single') {
        Get-OIMObject -ObjectName ESet -id $id
        return
    }

    $conditions = [Collections.Generic.List[string]]::new()
    if ($PSBoundParameters.ContainsKey('Ident_ESet')) { $conditions.Add("Ident_ESet = '$($Ident_ESet | ConvertTo-SQLLiteral)'") }
    if ($PSBoundParameters.ContainsKey('Where')) { $conditions.Add("($Where)") }

    $getParams = @{ ObjectName = 'ESet' }
    if ($conditions.Count -gt 0) { $getParams['Where'] = $conditions -join ' AND ' }
    if ($PSBoundParameters.ContainsKey('First')) { $getParams['First'] = $First }

    Get-OIMObject @getParams
}

function New-OIMESet {
    <#
    .SYNOPSIS
    Creates an ESet (entitlement set) object.

    .PARAMETER checkexists
    If an ESet with the given -Ident_ESet already exists, return it instead of creating a duplicate.
    Delegates to New-OIMObject's own Ident_<ObjectName> based existence check, which ESet's schema follows natively.

    .EXAMPLE
    New-OIMESet -Ident_ESet 'VPN Access' -DisplayName 'VPN Access'
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory = $true)]
        [Alias('Name')]
        [string]$Ident_ESet,

        [string]$DisplayName,

        [hashtable]$Properties = @{},

        [switch]$checkexists
    )

    $allProperties = @{ Ident_ESet = $Ident_ESet }
    if ($PSBoundParameters.ContainsKey('DisplayName')) { $allProperties['DisplayName'] = $DisplayName }
    foreach ($key in $Properties.Keys) { $allProperties[$key] = $Properties[$key] }

    if ($PSCmdlet.ShouldProcess($Ident_ESet, 'Create ESet')) {
        New-OIMObject -ObjectName ESet -Properties $allProperties -checkexists:$checkexists -Confirm:$false
    }
}

function Set-OIMESet {
    <#
    .SYNOPSIS
    Updates properties on one or more ESet objects.

    .EXAMPLE
    Get-OIMESet -Ident_ESet 'VPN Access' | Set-OIMESet -Properties @{Description = 'Remote access'}
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $Object,

        [Parameter(Mandatory = $true)]
        [hashtable]$Properties
    )

    Process {
        if ($PSCmdlet.ShouldProcess("$($Object.UID_ESet)", 'Update ESet')) {
            $Object | Set-OIMObject -Properties $Properties -Confirm:$false
        }
    }
}

function Remove-OIMESet {
    <#
    .SYNOPSIS
    Removes one or more ESet objects.

    .EXAMPLE
    Get-OIMESet -Ident_ESet 'VPN Access' | Remove-OIMESet
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $Object
    )

    Process {
        if ($PSCmdlet.ShouldProcess("$($Object.UID_ESet)", 'Remove ESet')) {
            $Object | Remove-OIMObject -Confirm:$false
        }
    }
}