Hudu – Check if all field is empty before deleting from layout

I was chatting to someone recently who was wondering if there was a quick way to see if a specific field was empty on in all assets in Hudu before deleting the field from the Asset Layout. I threw together this script to act as a workaround until its added to Hudu itself.

#####################################################################
# Get a Hudu API Key from https://yourhududomain.com/admin/api_keys
$HuduAPIKey = "YourHuduAPIKey"
# Set the base domain of your Hudu instance without a trailing /
$HuduBaseDomain = "https://your-hudu.domain"
$HuduAssetLayoutName = "Desktops / Laptops"
$HuduFieldName = "Warranty Expiry"

#Get the Hudu API Module if not installed
if (Get-Module -ListAvailable -Name HuduAPI) {
		Import-Module HuduAPI 
	} else {
		Install-Module HuduAPI -Force
		Import-Module HuduAPI
	}

$Layout = Get-HuduAssetLayouts -name $HuduAssetLayoutName
$Assets = Get-HuduAssets -assetlayoutid $layout.id
$values = $Assets.fields | where-object -filter {$_.label -eq $HuduFieldName} | select value
if ($values) {
$values
Write-Host "Warning $($values.count) $HuduFieldName fields found in $HuduAssetLayoutName" -Foregroundcolor Red
} else {
	Write-Host "No $HuduFieldName fields found in $HuduAssetLayoutName" -Foregroundcolor Green
}

You may also like...