functions/Get-SensorInvoice.ps1

 <#
    .SYNOPSIS
    Creates an report of all invoiced sensors of all customers. Also the servers and workstation are counted for each customer.
 
    .DESCRIPTION
    Creates an report of all invoiced sensors of all customers. Also the servers and workstation are counted for each customer.
    The count for server and workstation is evaluated now. It has no relation to the Month and Year given.
     
    .PARAMETER Year
    The Year for the Report.
 
    .PARAMETER Moth
    The Moth for the Report.
     
    .PARAMETER AuthToken
    Either a session or an API key. If no AuthToken is provided the global Server-Eye session will be used if available.
#>

function Get-SensorInvoice{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [int]$Year,
        [Parameter(Mandatory=$true)]
        [ValidateSet(1,2,3,4,5,6,7,8,9,10,11,12)]
        [int]$Month,
        [Parameter(ValueFromPipelineByPropertyName,ValueFromPipeline=$false)]
        [alias("ApiKey","Session")]
        $AuthToken
    )

    Begin{
        Update-SEHelper
        $AuthToken = Test-SEAuth -AuthToken $AuthToken
        Write-Warning "The count for server and workstation is evaluated now. It has no relation to the Month and Year given."
    }

    Process {

            $customers = Get-SECustomer -all -AuthToken $AuthToken  
            $usage = Get-SeApiCustomerUsageList -Year $year -Month $Month -AuthToken $AuthToken

        foreach ($customer in $customers) {
            $serverCount = (Get-SeApiCustomerContainerList -CId $customer.CustomerId -AuthToken $AuthToken | Where-Object {$_.isServer -eq $true -and $_.subtype -eq "2"}  | Measure-Object).Count
            $workstationCount = (Get-SeApiCustomerContainerList -CId $customer.CustomerId -AuthToken $AuthToken | Where-Object {$_.isServer -eq $false -and $_.subtype -eq "2"}  | Measure-Object).Count
            $usageCustomer = $usage | Where-Object customerNumberExtern -eq $customer.CustomerNumber
            [PSCustomObject]@{ 
                CustomerName = $customer.Name
                Container = $usageCustomer.container
                Sensors = $usageCustomer.agents
                NFR = $usageCustomer.nfr
                Subtotal = $usageCustomer.subtotal
                Antivirus = $usageCustomer.antivir
                Patchmanagement = $usageCustomer.patch
                Remotecontrol = $usageCustomer.pcvisit
                'Free Sensors' = $usageCustomer.free
                Total = $usageCustomer.total
                Server = $serverCount
                Workstation = $workstationCount
            }
        }
    }

    End{

    }
}








# SIG # Begin signature block
# MIIa4AYJKoZIhvcNAQcCoIIa0TCCGs0CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUTtZhOlZOcudMm/SsBeIorHmO
# W6SgghXRMIIEmTCCA4GgAwIBAgIPFojwOSVeY45pFDkH5jMLMA0GCSqGSIb3DQEB
# BQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQg
# TGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxITAfBgNV
# BAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdMBsGA1UEAxMUVVROLVVTRVJG
# aXJzdC1PYmplY3QwHhcNMTUxMjMxMDAwMDAwWhcNMTkwNzA5MTg0MDM2WjCBhDEL
# MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE
# BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKjAoBgNVBAMT
# IUNPTU9ETyBTSEEtMSBUaW1lIFN0YW1waW5nIFNpZ25lcjCCASIwDQYJKoZIhvcN
# AQEBBQADggEPADCCAQoCggEBAOnpPd/XNwjJHjiyUlNCbSLxscQGBGue/YJ0UEN9
# xqC7H075AnEmse9D2IOMSPznD5d6muuc3qajDjscRBh1jnilF2n+SRik4rtcTv6O
# KlR6UPDV9syR55l51955lNeWM/4Og74iv2MWLKPdKBuvPavql9LxvwQQ5z1IRf0f
# aGXBf1mZacAiMQxibqdcZQEhsGPEIhgn7ub80gA9Ry6ouIZWXQTcExclbhzfRA8V
# zbfbpVd2Qm8Aa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