Public/New-Scaler.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
<#
    .SYNOPSIS
    Creates an scalar object.

    .DESCRIPTION
    Creates the scalar JSON message in hashtable form to send to the eCC Salesforce API to accept measurements

    .INPUTS
    None. You cannot pipe objects to New-Scalar.

    .OUTPUTS
    A new PSCustomObject that contains the scalar data

    .PARAMETER MetricTypeCode
    The metric type code from the org metrics. See Get-MetricDefinitions

    .PARAMETER UnitTypeCode
    The unit type code from the org metrics. See Get-MetricDefinitions

    .PARAMETER Value
    The value in units specified by UnitTypeCode

    .PARAMETER DateTime
    The date/time of the scalar measurement.
#>

function New-Scalar {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [String]
        $MetricTypeCode,

        [Parameter(Mandatory = $true, Position = 1)]
        [String]
        $UnitTypeCode,

        [Parameter(Mandatory = $true, Position = 2)]
        [String]
        $Value,

        [Parameter(Mandatory = $true, Position = 3)]
        [System.DateTime]
        $DateTime
    )

    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }

    process {
        Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"
        Write-Output @{
            "attributes"                   = @{
                "type" = "Scalar__c"
            }
            "Metric_Type_Code__c"          = $MetricTypeCode
            "Value__c"                     = $Value
            "Unit_Type_Code__c"            = $UnitTypeCode
            "Observation_Date_Time__c"     = $DateTime
            "Observation_Result_Status__c" = "R"
            "Observation_Method__c"        = "AMEAS^auto-measurement^MDC"
        }
    }
}