Skip to main content
Question

Remove Pinned Devices From Inactive Accounts

  • March 11, 2026
  • 1 reply
  • 48 views

jorowi
Forum|alt.badge.img+1

I would like to remove pinned devices in our enterprise on accounts that have had no activity in 90 days. I wrote the following with the help of Gemini and it appears it will work. I’m new to the Box CLI so if anyone else with more experience can take a look at this I’d appreciate it.

 

# 1. Calculate the date 90 days ago in ISO 8601 format
$thresholdDate = (Get-Date).AddDays(-90)
Write-Host "Looking for users inactive since: $($thresholdDate.ToShortDateString())" -ForegroundColor Cyan

# 2. Get all users and filter by 'modified_at'
# Note: --max-items 5000 ensures we don't just get the first page
$inactiveUsers = box users --all-users --json --max-items 5000 | ConvertFrom-Json | Where-Object {
[datetime]$_.modified_at -lt $thresholdDate
}

if ($inactiveUsers.Count -eq 0) {
Write-Host "No inactive users found. Exiting." -ForegroundColor Green
exit
}

Write-Host "Found $($inactiveUsers.Count) inactive users. Fetching device pins..." -ForegroundColor Yellow

# 3. Get all enterprise device pins
$allPins = box device-pins --json --max-items 5000 | ConvertFrom-Json

# 4. Loop through inactive users and delete their pins
foreach ($user in $inactiveUsers) {
# Find pins belonging to this specific user
$userPins = $allPins | Where-Object { $_.owned_by.id -eq $user.id }

foreach ($pin in $userPins) {
Write-Host "Removing pin $($pin.id) ($($pin.product_name)) for user: $($user.name)" -ForegroundColor Magenta

# UNCOMMENT THE LINE BELOW TO ACTUALLY DELETE
# box device-pins:delete $($pin.id) --yes
}
}

Write-Host "Process complete." -ForegroundColor Green

 

1 reply

Hi ​@jorowi

Good start! but one important correction, this script does not reliably identify inactive users.

modified_at on box users is a profile timestamp, not true user activity. So it can miss active users or include users who are not actually inactive.

For a 90-day inactivity workflow, you should:

  1. Determine inactive users from Events / activity data (not users.modified_at).
  2. Use that inactive user list to drive your existing device-pins deletion loop.

A good reference our inactive users reports script

You can reuse the inactivity detection logic from that script and combine it with your pin-removal section

Regards,

Artur