How to automatically remove inactive users from TruGrid

Automating the removal of inactive users is feasible for Domain Administrators, although it is not supported as a built-in policy within Active Directory. To simplify administrative overhead, this functionality can be implemented via automation using  Active Directory and PowerShell scripting*


This guide describes the process of automatically removing inactive users from a designated Active Directory (AD) group used for TruGrid users syncThe primary goal of this automation is to:
  • Free up unused TruGrid licenses
  • Ensure licenses are allocated only to active users
  • Reduce manual administrative overhead, as Inactive users who remain in the TG-related AD group continue to consume licenses unnecessarily


Blow are listed steps to complete the automation for On-Premise Active Directory:
  1. 1. Create and Save the script

Save your script as a .ps1 file in Notepad,


Example of PowerShell script:


$daysInactive = 30  - "Desired number of days user has been inactive"
$cutoffDate = (Get-Date).AddDays(-$daysInactive)

$groupName = "TG-USERS" - "Group that is used by TruGrid to sync users"

$users = Get-ADGroupMember $groupName | Where-Object { $_.objectClass -eq "user" }

foreach ($user in $users) {
$adUser = Get-ADUser $user.SamAccountName -Properties LastLogonDate

if ($adUser.LastLogonDate -lt $cutoffDate) {
Remove-ADGroupMember -Identity $groupName -Members $user -Confirm:$false
Write-Output "Removed $($user.SamAccountName)"
}
}


  1. Open Task Scheduler and create New Basic Taks


  1. Schedule time period when task should run Daily/Weekly/Monthly



  1. Action - set "Start Program"



  • Program/Script: PowerShell.exe
  • Argument: -ExecutionPolicy Bypass -File "C:\Scripts\RemoveInactiveUsersFromGroup.ps1"
  • Start in: *-C:\Scripts*

  1. Once Task is created you could run it manually to test it out





Updated on: 27/03/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!