PowerShell

Track Ubiquiti Unifi Stock, and get notified of changes

I am a pretty big fan of Ubiquiti and their Unifi products line. Whether it's network equipment or their camera systems, Unifi Protect, I have it all, and I'm pretty happy with how it works. However, over the last two years, some of their stocks in the store were very hard to find. For example, I've searched for Unifi Protect G4 Doorbell Pro for over six months. I've tried local shops all around Europe, even in the Ubiquiti Europe store, never to see them.

The thing is, I am not the only one. If you go to Reddit's very own community, Ubiquiti, plenty of people are searching for different products and waiting for them to be dropped into the store. There is even a dedicated r/UbiquitiInStock community where a bot shows what's in the store and what goes out. After trying it out, I've noticed that getting notifications from Reddit was always too late for me because of the delay. There were just many false positives for me because I was only searching for specific products while the notifications were coming all day for different ones. And while waiting for Unifi G4 DoorBell Pro for over a week, I've not seen a single drop, but at the same time, I saw plenty of other equipment that I was not interested in. While other tracking services could help, or I could buy it secondhand for two times the vendor price, I decided that it's better to try and write my tracker and see if it can help me.

Using PowerShell to find Ubiquiti stock on Unifi Store

If you know my work, you would know I would use PowerShell to achieve my goals. After playing with the Unifi Store backend, I've created a small PowerShell module to help me get the Doorbell I wanted! This PowerShell Module is tiny and has only two functions Get-UnifiStock and Wait-UnifiStock. The first one I've created allows for an accessible overview of what's in store when checking different collections of products, while Wait-UnifiStock is to be directly used when waiting for something.

Get-UnifiStock -Store USA -Collection Protect, ProtectAccessories, ProtectNVR | Sort-Object -Property Name | Format-Table

With a simple one-line of code that you can copy and paste into a PowerShell Window (Press Start, type PowerShell, and press enter), you can now play with Unifi Stock from different Ubiquiti stores around the world. The following query shows a query to the Unifi Store in Europe with the requirement of returning only Protect and NetworkWIFI devices. Then we use Sort-Object to sort the data produced by the Shop by Name and force the output into a table.

Get-UnifiStock -Store Europe -Collection Protect, NetworkWifi | Sort-Object -Property Name | Format-Table

You can skip parameter collections and ask for everything the shop has in store.

Get-UnifiStock -Store Europe | Sort-Object -Property Name | Format-Table

With some PowerShell magic, you could find out which products are currently out of stock. Using Where-Object and property Available, we ask the query only to return unavailable products.

Get-UnifiStock -Store Europe | Where-Object { $_.Available -eq $false } | Sort-Object -Property Name | Format-Table

While Get-UnifiStock is helpful, it's mostly to find out the names, categories, or SKU numbers that can be later on used in the Wait-UnifiStock command.

Waiting for the right product on Unifi Store

Wait-UnifiStock is the simple command that helps to get notified when the stock is in. When you run that command, it doe the followings:

  • Wait for the given product to appear in store or use the given interval (default every 60 seconds)
  • When the product shows up as available, it will:
    • Use speech synthesis to say: β€œHey, there is stock available for XXX.”
    • Open a website in your default browser directly on the product you want to buy and bring it to the front.

It's pretty simple in what it does, but it's what I needed.

Wait-UnifiStock -ProductName 'Access Point AC Lite' -Seconds 60

Wait-UnifiStock -ProductName 'UniFi6 Mesh', 'G4 Doorbell Pro', 'Camera G4 Pro', 'Test' -Seconds 60

Wait-UnifiStock -ProductSKU 'UDR-EU' -ProductName 'Switch Flex XG' -Seconds 60

The above example shows that you can use ProductName or ProductSKU (or both) to wait for the product you need. You can also query multiple products at once, and the ones that do not exist (typos) will be ignored. You can also control refresh time by using the Seconds parameter. If you skip it, the default value will be every 60 seconds which is good enough to find what you need. Remember that using anything below 60 seconds may be tempting, but it may get you blocked. This is because you're querying API every 60 seconds. If you change it to 5, antispam filters may kick in and deny further requests to API and the whole website. Please be responsible!

UnifiStockTracker supports Ubiquiti shops in 9 different countries: Brazil and China, Europe, India, Japan, Mexico, Singapore, Taiwan, and the USA. When you choose the Store parameter, you will get autocomplete for that. Like Collection, you will get autocomplete in one of the available options: NetworkOS, NetworkSmartPower, NetworkWifi, ProtectAccessories, NetworkRoutingOffload, NetworkSwitching, Protect, or ProtectNVR.

Installing UnifiStockTracker PowerShell module

If you would like to use this PowerShell module all you need to do is open PowerShell, and type

Install-Module UnifiStockTracker -Force -Verbose -Scope CurrentUser

Once you do this, you can use the commands mentioned above. The module is downloaded from PowerShellGallery hosted by Microsoft. If you want to review sources or add some features feel free to explore UnifiStockTracker on GitHub.

This post was last modified on April 16, 2023 20:25

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

6 days ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

4 months ago

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

8 months ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

1 year ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

1 year ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

1 year ago