Public/Disconnect-IdoIt.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
function Disconnect-IdoIt {
    <#
        .SYNOPSIS
        Disconnect-IdoIt destroys the session to idoit and removes all session variables

        .DESCRIPTION
        Disconnect-IdoIt destroys the session to idoit and removes all session variables

        .EXAMPLE
        PS> Disconnect-IdoIt

        This will disconnect from idoit

        .NOTES
        Version
        0.1.0 29.12.2017 CB initial release
        0.2.0 01.01.2018 CB added removal of variable CmdbUri from global scope; Added Try/Catch Block
    #>


    $Params = @{}

    #Todo Check if a session is available before destroing
    Try {
        Invoke-IdoIt -Method "idoit.logout" -Params $Params
    }
    Catch {
        Throw
    }

    Remove-Variable -Name CmdbApiKey -Scope Global -Force:$true
    Remove-Variable -Name CmdbSession -Scope Global -Force:$true
    Remove-Variable -Name CmdbUri -Scope Global -Force:$true

}