Skip to content

Instantly share code, notes, and snippets.

Last active May 20, 2020
What would you like to do?
function Get-OlkbOrder {
Checks for a given order on to determine the current place in line for shipping. Optionally stores the
place in line in a file on disk.
Parses the current orders markdown file on github for orders, searching for a given order number. When
found, the order number and place in line is output. If the option for tracking is provided, the current place in line
is compared to the previously stored place in line and the difference is displayed.
PS C:\> Get-OlkBorder -OrderNumber 100005999 -TrackOrder:$false
Checks order number 100005999 for current place in line and outputs the result. The status is not persistent (i.e. is not
saved to disk)
PS C:\> iex ((New-Object System.Net.WebClient).DownloadString('')); Get-OlkbOrder
Loads the function into memory from github and executes Get-OlkbOrder with default options.
[System.String] $OrderNumber = '100007911',
[Switch] $TrackOrder = $true,
[System.String] $TrackingFile = "olkborder.xml"
begin {
# Attempt to load required modules
try {
Import-Module psmarkdown -ErrorAction Stop
catch {
Throw "Error loading psmarkdown module: $_"
# Try to grab the current raw order list
try {
$Raw = Invoke-WebRequest -Uri -ErrorAction Stop
catch {
Write-Debug "Something went wrong invoking web request. Debug?"
throw "Something went wrong invoking web request."
# Grab the content and convert it from markdown
$Content = $Raw.content
$PsObj = $Content | ConvertFrom-Markdown -WarningAction SilentlyContinue
# Find this order entry in the resulting object
$OrderEntry = ($PsObj -match $OrderNumber).H1
# If we can't find the order, or if there's multiple orders, then throw an error.
if (! $OrderEntry.Count) {
Write-Debug "Order not found, debug?"
throw "Order not found"
elseif ($OrderEntry.count -ne 1) {
Write-Debug "Issue while filtering for order $OrderNumber, debug?"
throw "Issue while filtering for order $OrderNumber"
# Create a custom order object derived from the current date and the Order entry (in the format [Place in line].[Order Number])
$Order = [PScustomObject] @{
PlaceInLine = $OrderEntry.Split('.')[0]
OrderNumber = $OrderNumber
Date = Get-Date
# Output to the information stream the order/place in line
Write-Information -InformationAction Continue "Order: $($Order.OrderNumber), Place in line: $($Order.PlaceInLine)"
# If we're using persistent tracking, do more work
if ($TrackOrder) {
# If the tracking file doesn't exist, just export the order object to the tracking file.
if (!(Test-Path -Path $TrackingFile -Type Leaf)){
$Order | Export-Clixml -Path $TrackingFile
else {
# If the tracking file does exist, grab the old status
$OldStatus = Import-Clixml -Path $TrackingFile
# Compare the old status to the current order object to find how many spots we've moved up
$PlaceProgress = $OldStatus.PlaceInLine - $Order.PlaceInLine
# Compare the old status to the current order object to find how long it has been since our last order update
$DateProgress = $Order.Date - $OldStatus.Date
# Output to the information stream
$Message = "You've moved up [ $PlaceProgress ] in $($DateProgress.Days) Days, $($DateProgress.Hours) Hours, $($DateProgress.Minutes) Minutes"
Write-Information -InformationAction Continue -MessageData $Message
# If we've moved up or down in our place in line, export the current order to the tracking file.
if ($PlaceProgress -ne 0) {
$Order | Export-Clixml -Path $TrackingFile
Write-Debug -Message "About to leave $($MyInvocation.MyCommand.Name), debug?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment