Public/APICore/Session/Set-GlpiToolsKillSession.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
<#
.SYNOPSIS
    Function which kill API session.
.DESCRIPTION
    Function gets nesessery information from Config file, and Function Set-GlpiToolsInitSession, then kill session.
.PARAMETER SessionToken
    This parameter have to be passed from Set-GlpiToolsInitSession
.EXAMPLE
    PS C:\Users\Wojtek> $SessionToken | Set-GlpiToolsKillSession
    Run command like that and you will kill session with API GLPI
.EXAMPLE
    PS C:\Users\Wojtek> Set-GlpiToolsKillSession -SessionToken $SessionToken
    Run command like that and you will kill session with API GLPI
.INPUTS
    SessionToken from Set-GlpiToolsInitSession
.OUTPUTS
    None
.NOTES
    PSP 12/2018
#>


function Set-GlpiToolsKillSession {
    [CmdletBinding()]
    param (
        [parameter(Mandatory = $false)]
        [string]$SessionToken
    )
    
    begin {

        $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)/killSession/" 
        }
        Invoke-RestMethod @params | Out-Null
    }
    
    end {
    }
}