Public/Get-AMTDevice.ps1

function Get-AMTDevice {
    <#
        .SYNOPSIS
        List one or multiple devices which are registered on the Open AMT MPS server.
        
        .DESCRIPTION
        List one or multiple devices which are registered on the Open AMT MPS server.

        .PARAMETER Name
        Specify a device name to only return a specific device.

        .PARAMETER GUID
        Specify a device GUID to only return a specific device.

        .INPUTS
        You can pipe one or more device names into Get-AMTDevice.

        .OUTPUTS
        System.Object

        .EXAMPLE
        PS> Get-AMTDevice

        TenantID :
        Tags : {Store1,London}
        Hostname : Client-01
        MPSInstance : mps
        ConnectionStatus : True
        MPSUsername : admin
        GUID : 1ada9c84-780e-4ccc-831c-0edb26994b18

        TenantID :
        Tags : {Store2,NewYork}
        Hostname : Device-09
        MPSInstance :
        ConnectionStatus : False
        MPSUsername : admin
        GUID : 39270bdb-9488-4695-8f8f-0d9e5366c54e
        ...

        .EXAMPLE
        PS> Get-AMTDevice -Name Client-01

        TenantID :
        Tags : {Store1,London}
        Hostname : Client-01
        MPSInstance : mps
        ConnectionStatus : True
        MPSUsername : admin
        GUID : 1ada9c84-780e-4ccc-831c-0edb26994b18

        .EXAMPLE
        PS> Get-AMTDevice -GUID 1ada9c84-780e-4ccc-831c-0edb26994b18

        TenantID :
        Tags : {Store1,London}
        Hostname : Client-01
        MPSInstance : mps
        ConnectionStatus : True
        MPSUsername : admin
        GUID : 1ada9c84-780e-4ccc-831c-0edb26994b18

        .EXAMPLE
        PS> "Client-01","Client-02" | Get-AMTDevice

        TenantID :
        Tags : {Store1,London}
        Hostname : Client-01
        MPSInstance : mps
        ConnectionStatus : True
        MPSUsername : admin
        GUID : 1ada9c84-780e-4ccc-831c-0edb26994b18

        TenantID :
        Tags : {Store2,London}
        Hostname : Client-02
        MPSInstance : mps
        ConnectionStatus : True
        MPSUsername : admin
        GUID : 93525960-b4b5-4148-81e3-48a3d214a637

        .LINK
        Online version: https://github.com/netricsag/PowerAMT/tree/main/Docs

    #>


    param (
        [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)][string]$Name,
        [Parameter(ValueFromPipelineByPropertyName)][string]$GUID
    )

    begin {
        if($null -eq $Global:AMTSession){
            throw "No active AMT session. Create a session first with Connect-AMTManagement"
        }
    }
    
    process {
        $headers=@{}
        $headers.Add("Authorization", "Bearer $($Global:AMTSession.Token)")
        
        if(-not $Name -and -not $GUID) {
            $returnArray = @()
            $ResponseArray = Invoke-RestMethod -Uri ("https://" + $Global:AMTSession.Address + "/mps/api/v1/devices/") -Method GET -Headers $headers
    
            foreach($Response in $ResponseArray){
                $returnObject = New-Object -TypeName PSObject -Property @{
                    "GUID" = $Response.GUID
                    "Hostname" = $Response.hostname
                    "Tags" = $Response.tags
                    "MPSInstance" = $Response.MPSInstance
                    "ConnectionStatus" = $Response.ConnectionStatus
                    "MPSUsername" = $Response.MPSUsername
                    "TenantID" = $Response.tenantid
                }
                $returnArray += $returnObject
            }
            return $returnArray
        }
    
        if($null -ne $Name -and  $Name -ne ""){
            $returnArray = @()
            $ResponseArray = Invoke-RestMethod -Uri ("https://" + $Global:AMTSession.Address + "/mps/api/v1/devices/") -Method GET -Headers $headers
            
            foreach($Response in $ResponseArray){
                $returnObject = New-Object -TypeName PSObject -Property @{
                    "GUID" = $Response.GUID
                    "Hostname" = $Response.hostname
                    "Tags" = $Response.tags
                    "MPSInstance" = $Response.MPSInstance
                    "ConnectionStatus" = $Response.ConnectionStatus
                    "MPSUsername" = $Response.MPSUsername
                    "TenantID" = $Response.tenantid
                }
                $returnArray += $returnObject
            }
            return $returnArray | Where-Object {$_.hostname -eq $Name}
        }
    
        if($null -ne $GUID -and $GUID -ne ""){
            return (Invoke-RestMethod -Uri ("https://" + $Global:AMTSession.Address + "/mps/api/v1/devices/$GUID") -Method GET -Headers $headers)
        }
    }
    
}