Get-BillingEntries
  • 3 Minutes to read
  • Dark
    Light
  • PDF

Get-BillingEntries

  • Dark
    Light
  • PDF

Article summary

Summary

Retrieves a collection of billing entry field cache objects.

Get-BillingEntries
    -Top
    -Skip
    -Filter
    -OrderBy

Returns a collection object with the following properties:

Property

Type

Notes

Collection

Collection of billing entry field cache objects

The collection of entries retrieved after top, skip, filter, and order by parameters were applied.

Top

Int32

The top parameter value that was used. Useful while paging data.

Skip

Int32

The skip parameter value that was used. Useful while paging data.

TotalCount

Int32

The total count of records available after any filtering was applied. Useful while paging data.

Field Cache Objects

Field cache objects cannot be used directly for updating an object using a Set-* command. Instead, you will need to retrieve the object you intend to update directly using a Get-* command, modify the properties you want to update, and then save that object back using a Set-* command.

Parameters

Parameter

Type

Required?

Notes

Top

Int32

No, Defaults to 40

Total number of entries to retrieve. Max is 1000.

Skip

Int32

No, Defaults to 0

How many entries should be skipped within the collection. Used for paging the results.

Filter

String

No

An OData 4 string that can be used for filtering the collection.

OrderBy

String

No

An OData 4 string that can be used for sorting the collection by specific fields.

Examples

Get a collection of billing entries

# This sample shows how to use filtering, ordering, and paging to iterate through all of the matching data.

$top = 1000
$skip = 0
$page = 1

$usCulture = [Globalization.CultureInfo]::GetCultureInfo("en-US")


# In this filtering example, we want to retrieve all billing entries, but only for the current month.
# Billing entries are stored on the server in UTC time, so to get an accurate representation of the current month,
# we need to convert the current date to a local time zone, and then apply the filter.

# Get current DateTime in local time zone
$currentDate = Get-Date

# Convert to Central Standard Time
$cstZone = [TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time")
$currentCSTDate = [TimeZoneInfo]::ConvertTime($currentDate, $cstZone)

# Lastly, get the first day of the current year. Note that we need to convert the date to a string
# format, or the server will throw an error.
$firstDayOfTheYear = (Get-Date `
    -Year $currentCSTDate.Year `
    -Month 1 `
    -Day 1).ToString("yyyy-MM-ddTHH:mm:ssK")

# Add a filter and orderBy
$filter = "Date ge $($firstDayOfTheYear)"
$orderBy = "Date"

do {
  $billingEntries = Get-BillingEntries `
    -Filter $filter `
    -OrderBy $orderBy `
    -Top $top `
    -Skip $skip

  Write-Output ">> Page $page Results <<"

  $collectionType = $billingEntries.GetType()
  Write-Output "Type of Collection: $($collectionType.FullName)"

  $billingEntries.Collection | ForEach-Object {
    $localDate = [TimeZoneInfo]::ConvertTime($_.Date, $cstZone).ToString("yyyy-MM-dd")
    "[$($localDate)] Id: $($_.BillingEntryId) | $($_.BillingTypeDescription) | Qty: $($_.Quantity) | Price: $($_.UnitPrice.ToString('C', $usCulture)) | Total: $(($_.Quantity * $_.UnitPrice).ToString('C', $usCulture))"
  }

  Write-Output "Total Count: $($billingEntries.TotalCount)"
  
  # Calculate the sum of the billing entries. Here, we can use the Measure-Object cmdlet
  $sum = ($billingEntries.Collection | Measure-Object -Property { $_.Quantity * $_.UnitPrice } -Sum).Sum
    Write-Output "Total Sum: $($sum.ToString('C', $usCulture))"

  Write-Output ""

  $skip += $top
  $page += 1
} while ($skip -lt $billingEntries.TotalCount)

Results of executing the script:

>> Page 1 Results <<
[2023-01-27] Id: 88876 | Processing | Qty: 100.00 | Price: $100.00 | Total: $10,000.00
[2023-01-27] Id: 88877 | Discovery | Qty: 1.00 | Price: $15.00 | Total: $15.00
[2023-01-28] Id: 88878 | Staging | Qty: 5.00 | Price: $0.00 | Total: $0.00
[2023-02-01] Id: 88880 | Hosting | Qty: 1.00 | Price: $100.00 | Total: $100.00
[2023-02-01] Id: 88881 | Discovery | Qty: 1.00 | Price: $5.00 | Total: $5.00
[2023-02-02] Id: 88882 | Redacting | Qty: 25.00 | Price: $1.50 | Total: $37.50
[2023-02-02] Id: 88883 | Discovery | Qty: 10.00 | Price: $15.00 | Total: $150.00
[2023-02-02] Id: 88884 | Relativity Hosting | Qty: 5.00 | Price: $5.00 | Total: $25.00
[2023-02-02] Id: 88885 | Relativity Hosting | Qty: 12.00 | Price: $5.00 | Total: $60.00
[2023-02-02] Id: 88886 | Relativity Hosting | Qty: 9.00 | Price: $5.00 | Total: $45.00
Total Count: 146
Total Sum: $10,437.50

>> Page 2 Results <<
[2023-02-02] Id: 88887 | Processing | Qty: 15.00 | Price: $75.00 | Total: $1,125.00
[2023-02-02] Id: 88888 | Consulting | Qty: 1.00 | Price: $125.00 | Total: $125.00
[2023-02-02] Id: 88890 | Consulting | Qty: 15.00 | Price: $175.00 | Total: $2,625.00
[2023-02-02] Id: 88891 | Voids | Qty: 13.00 | Price: $0.00 | Total: $0.00
[2023-02-02] Id: 88892 | Relativity Hosting | Qty: 15.00 | Price: $5.00 | Total: $75.00
[2023-02-02] Id: 88893 | Hosting | Qty: 1256.00 | Price: $100.00 | Total: $125,600.00
[2023-02-02] Id: 88894 | Indexing (Electronic) | Qty: 1000.00 | Price: $1.00 | Total: $1,000.00
[2023-02-02] Id: 88895 | OCR | Qty: 156.00 | Price: $0.03 | Total: $4.68
[2023-02-02] Id: 88896 | DVD Duplication | Qty: 5.00 | Price: $2.00 | Total: $10.00
[2023-02-02] Id: 88897 | Endorsement (Electronic) | Qty: 15.00 | Price: $0.01 | Total: $0.15
Total Count: 146
Total Sum: $130,564.83

(Further results removed)