> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.trugrid.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 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 **&#160;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)"
    }
}
```

2. Open Task Scheduler and create New Basic Taks
![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-sult_vb46qt.png =777x432)

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

![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-suur_v4xc59.png =666x467)
![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-svcb_1wnh54i.png =666x465)

4. Action - set "**Start  Program**"

![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-svgb_bcri1f.png =666x466)

* **Program/Script:**  *PowerShell.exe*
* **Argument:** *-ExecutionPolicy Bypass -File "C:\Scripts\RemoveInactiveUsersFromGroup.ps1"*
* **Start in: ***-C:\Scripts*
![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-sxvb_1nkh35z.png =666x466)
5. Once Task is created you could run it manually to test it out

![](https://storage.crisp.chat/users/helpdesk/website/-/f/4/7/3/f473d72e7d7c5000/scr-20260324-sycp_182byqi.png =888x635)