Public/APICore/Profiles/Get-GlpiToolsActiveProfile.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
<#
.SYNOPSIS
    Function Return the current active profile.
.DESCRIPTION
    Function Return the current active profile.
.EXAMPLE
    PS C:\> Get-GlpiToolsActiveProfile
    Function Return the current active profile.
.INPUTS
    None
.OUTPUTS
    Function returns PSCustomObject with property's of Active Profile current logged user in GLPI
.NOTES
    PSP 04/2019
#>


function Get-GlpiToolsActiveProfile {
    [CmdletBinding()]
    param (
        
    )
    
    begin {
        $SessionToken = $Script:SessionToken
        $AppToken = $Script:AppToken
        $PathToGlpi = $Script:PathToGlpi

        $SessionToken = Set-GlpiToolsInitSession | Select-Object -ExpandProperty SessionToken
        $AppToken = Get-GlpiToolsConfig | Select-Object -ExpandProperty AppToken
        $PathToGlpi = Get-GlpiToolsConfig | Select-Object -ExpandProperty PathToGlpi
    }
    
    process {
        $params = @{
            headers = @{
                'Content-Type'  = 'application/json'
                'App-Token'     = $AppToken
                'Session-Token' = $SessionToken
            }
            method  = 'get'
            uri     = "$($PathToGlpi)/getActiveProfile/"
        }
            
        $ActiveProfile = Invoke-RestMethod @params

        $ActiveProfile.active_profile
    }
    
    end {
        Set-GlpiToolsKillSession -SessionToken $SessionToken
    }
}