Public/Setup/Plugins/FusionInventory/Get-GlpiToolsFusionInventoryUnmanaged.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<#
.SYNOPSIS
    Function to show Fusion Unmanaged Devices from GLPI
.DESCRIPTION
    Function to show Fusion Unmanaged Devices from GLPI. Function will show Unmanaged Devices, which are in GLPI, not on Fusions
.EXAMPLE
    PS C:\> Get-GlpiToolsFusionUnmanaged Devices
    Function will show all Unmanaged Devices which are available in GLPI
.INPUTS
    Inputs (if any)
.OUTPUTS
    Function returns PSCustomObject
.NOTES
    PSP 01/2019
#>


function Get-GlpiToolsFusionInventoryUnmanaged {
    [CmdletBinding()]
    param (
        
    )
    
    begin {

        $InvocationCommand = $MyInvocation.MyCommand.Name

        if (Check-GlpiToolsPluginExist -InvocationCommand $InvocationCommand) {

        } else {
            throw "You don't have this plugin Enabled in GLPI"
        }

        $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

        $UnmanagedArray = [System.Collections.Generic.List[PSObject]]::New()
    }
    
    process {
        $params = @{
            headers = @{
                'Content-Type'  = 'application/json'
                'App-Token'     = $AppToken
                'Session-Token' = $SessionToken
            }
            method  = 'get'
            uri     = "$($PathToGlpi)/PluginFusioninventoryUnmanaged/?range=0-999999999" 
        }
        $AllFusionUnmanaged = Invoke-RestMethod @params

        foreach ($FusionUnmanaged in $AllFusionUnmanaged) {
            $FusionHash = [ordered]@{ }
                    $FusionProperties = $FusionUnmanaged.PSObject.Properties | Select-Object -Property Name, Value 
                        
                    foreach ($FusionProp in $FusionProperties) {
                        $FusionHash.Add($FusionProp.Name, $FusionProp.Value)
                    }
                    $object = [pscustomobject]$FusionHash
                    $UnmanagedArray.Add($object)
        }
        $UnmanagedArray
        $UnmanagedArray = [System.Collections.Generic.List[PSObject]]::New()
    }
    
    end {
        Set-GlpiToolsKillSession -SessionToken $SessionToken
    }
}