EASYENTRA Blog

News & Updates

Automate Hybrid User Offboarding with EasyEntra and Windows Task Scheduler 

Automate Hybrid User Deprovisioning with EasyEntra

If you manage a hybrid IT environment, you already know the dread of the “Employee Offboarding” ticket.

It sounds simple on paper. In reality? It’s a disjointed, frustrating scavenger hunt. You find yourself logging into an on-premises Domain Controller to disable the user and move to a different OU. Then you hop over to the Exchange Admin Center to convert the mailbox. Next, you jump into the Microsoft Entra portal to revoke refresh tokens, wipe MFA methods, and strip licenses. Finally, you head to the SharePoint Admin Center to handle their OneDrive data.

It easily takes 30 minutes of manual clicking per user. It is repetitive and prone to human error. If you miss just one step, you leave a massive security gap wide open. But there had to be a better way, right? This comprehensive guide walks you through building a resilient, zero-touch offboarding pipeline!

The Architecture of Automated Offboarding Engine

Before we look at the commands, let’s look at the operational flow.

  • Trigger Initialized: An HR system or helpdesk agent drops a plain .txt file containing the target user’s email into C:\EasyEntra\Offboarding\Input\.
  • Automation Polling: Windows Task Scheduler wakes up on a recurring frequency and launches the background engine under the service account profile.
  • EasyEntra Processing: The script reads the username and executes Invoke-EEDecommissionHybridUser to modify local Active Directory and Cloud Entra ID simultaneously.
  • Success Path: Successfully processed text files are cleanly migrated out of the queue and stored inside C:\EasyEntra\Offboarding\Done\.
  • Failure Path: Broken files or unrecognized identities are quarantined inside C:\EasyEntra\Offboarding\Error\, while the system writes the exact error code to C:\EasyEntra\Offboarding\Logs\.

To make this completely secure and automated, do not use personal administrator account. Let’s begin by creating and configuring the service account required for the offboarding automation.

Step 1: Create the Service Account (Active Directory & Entra ID)

To run unattended background tasks safely, you must establish a dedicated identity with the exact minimum permissions required.

1. On-Premises Active Directory Setup

  1. Open Active Directory Users and Computers (dsa.msc) or EasyEntra.
  2. Navigate to your managed Service Accounts Organisational Unit (OU).
  3. Create a new user account named svc.EEAutomation.
  4. Set a strong password, check Password never expires, and clear User must change password at next logon.

To trigger synchronization immediately, click the Entra Connect delta synchronization button in EasyEntra to invoke synchronization of Entra ID from AD.

After the service account creation,

  1. Open Local Security Policy (secpol.msc) on the machine running the automation script.
  2. Navigate to Local Policies > User Rights Assignment > Log on as a batch job.
  3. Click Add User or Group…, add svc.EEAutomation, and save changes.

2. Microsoft Entra ID Cloud Setup

  1. Log into the Microsoft Entra Admin Center as a Global Administrator.
  2. Ensure the hybrid identity for svc.EEAutomation has synced cleanly from your on-premises AD via Microsoft Entra Connect.

Step 2: Establish the File Trigger Folder Structure

The automation requires a dedicated workspace directory on the local C: drive of your management execution machine to process job lifecycles. Ensure the dedicated service account has read and write access to all workspace folders so it can process, update, and move job files as required.

Create the following nested directories exactly as shown below:

  • C:\EasyEntra\Scripts\ – Houses the production automation script.
  • C:\EasyEntra\Offboarding\Input\ – The Trigger Folder where files are dumped to start an offboarding.
  • C:\EasyEntra\Offboarding\Done\ – The storage vault where successfully processed files automatically migrate.
  • C:\EasyEntra\Offboarding\Error\ – The quarantine area where files with structural or user errors are safely isolated.
  • C:\EasyEntra\Offboarding\Logs\ – Contains chronological daily activity tracking logs for audit trails.

Step 3: Deploy the Core Offboarding Automation Script

Save the following optimized, script as Run-EasyEntraOffboarding.ps1 inside C:\EasyEntra\Scripts\.

$InputFolder = "C:\EasyEntra\Offboarding\Input"
$DoneFolder  = "C:\EasyEntra\Offboarding\Done"
$ErrorFolder = "C:\EasyEntra\Offboarding\Error"
$LogFolder   = "C:\EasyEntra\Offboarding\Logs"
$LogFile = Join-Path $LogFolder "Offboarding-$(Get-Date -Format 'yyyy-MM-ddTHH-mm-ss').log"
function Write-Log {
    param([string]$Message)
    "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')  $Message" |
        Out-File -FilePath $LogFile -Append -Encoding UTF8
}
Write-Log "Script launched..."
Import-Module "C:\Program Files\PowerShell\7\Modules\EasyEntraPS\EasyEntraPS.psd1" -Force
Write-Log "Exported: $((Get-Module -ListAvailable EasyEntraPS).ExportedCommands.Keys -join ', ')"
$Files = Get-ChildItem -Path $InputFolder -File -Filter "*.txt"
foreach ($File in $Files) {
    try {
        $Identity = (Get-Content $File.FullName -Raw).Trim()
        if ([string]::IsNullOrWhiteSpace($Identity)) {
            throw "Trigger file is empty."
        }
        Write-Log "Starting offboarding for $Identity from file $($File.Name)"
        $Result = Invoke-EEDecommissionHybridUser `
            -Identity $Identity `
            -Confirm:$false
        # FIXED LINE BELOW: Isolate $Identity from the colon
        Write-Log "Status for ${Identity}: $($Result.Status)"
        if ($Result.TaskLog) {
            foreach ($Entry in $Result.TaskLog) {
                Write-Log "[$($Entry.Status)] $($Entry.Task) $($Entry.Message)"
            }
        }
        if ($Result.Status -eq "FatalError") {
            throw "EasyEntra returned FatalError for $Identity"
        }
        Move-Item $File.FullName -Destination (Join-Path $DoneFolder $File.Name) -Force
        Write-Log "Moved $($File.Name) to Done."
    }
    catch {
        Write-Log "ERROR processing $($File.Name): $_"
        Move-Item $File.FullName -Destination (Join-Path $ErrorFolder $File.Name) -Force
    }
}

Step 4: Interactive Setup & EasyEntra Profile Authentication

EasyEntra stores its connection profile configuration within the current user’s profile folder. Because of this, you must perform the initial configuration and authentication while logged in as the dedicated service account (svc.EEAutomation) that will later run the automation.

  1. Open a PowerShell 7 terminal and change your working directory:
    cd “C:\Program Files\EasyEntra”
  2. Execute the graphical configuration application: .\EasyEntra.exe
  3. Log into service account created above (svc.EEAutomation).

After configuring PowerShell with the service account, open EasyEntra application.

  1. Open Connection Manager and select AD Connections > Click Add New.
  2. Complete the interactive authentication login using the credentials for svc.EEAutomation.

Step 5: Configure the Task Schedular to Automate Offboarding PowerShell Script

To ensure the script loops, checks for files, and executes in the proper profile context, map it inside Windows Task Scheduler.

  1. Open Task Scheduler (taskschd.msc).
  2. Right-click and choose Create Task.
  3. Under the General Tab:
    • Name: EE User Offboarding
    • Click Change User or Group and change the executing account to svc.EEAutomation.
  4. Toggle Run whether user is logged on or not.
  5. Check Run with highest privileges.

Now, configure the below under the Triggers Tab. Click New.

  1. Begin the task: On a schedule.
  2. Settings: Daily.
  3. Check Repeat task every: > select or type 15 minutes (or your preferred polling frequency).
  4. Duration of: Indefinitely.
  5. Ensure Enabled is checked.

Finally, under the Actions Tab, click New and configure the following.

  1. Action: Start a program
  2. Program/script: “C:\Program Files\PowerShell\7\pwsh.exe”
  3. Add arguments (optional): -ExecutionPolicy Bypass -File “C:\EasyEntra\Scripts\Run-EasyEntraOffboarding.ps1”
  4. Start in (optional): C:\EasyEntra\Scripts

Click OK to save. Enter the password for svc.EEAutomation when prompted.

Step 6: Trigger an Employee Offboarding

When you want to offboard someone, follow this exact physical folder path workflow.

  1. Open your File Explorer and navigate to your active trigger directory:
    C:\EasyEntra\Offboarding\Input\
  2. Drop the UPN of the user you want to offboard in .txt file directly into this folder.

3. What happens next:

    • When Task Scheduler wakes up (or when you trigger it manually), the script instantly locks onto that .txt file, opens it, and extracts the username string.
    • After processing the offboarding commands via EasyEntra, the script will cleanly delete the file from the Input folder and move a copy of it into C:\EasyEntra\Offboarding\Done\ (or \Error\ if it fails).
    • If the Invoke-EEDecommissionHybridUser command encounters an issue, such as a typo in the username, a network timeout, or expired service account credentials, the offboarding job is marked as failed. The .txt file is physically moved out of C:\EasyEntra\Offboarding\Input\ and dropped directly into: C:\EasyEntra\Offboarding\Error\

4. You can check the Logs folder to track everything the script does, whether it succeeds or fails. The last few lines will tell you the exact error message (like a missing connection or a user not found) so you know exactly how to fix it.

That’s it! By combining EasyEntra, a dedicated service account, PowerShell automation, and Windows Task Scheduler, you can transform employee offboarding from a lengthy manual process into a reliable, unattended workflow.

This approach not only reduces administrative effort but also minimizes the risk of missed steps, improves security by enforcing least-privilege access, and provides a scalable solution for organizations managing hybrid Active Directory and Microsoft Entra environments!

Free 30-minute demo

try 30 days for free

GET EASYENTRA NEWS

Opt out at any time

“One of the best products I've used.”
Gary Shurland
Chief Information Officer, Mirick, United States
“This tool has been invaluable in streamlining our IT processes.”
Tyson Mckay
Chief Information Officer, Southwest Network, United States
“This product has been a miracle for our Help Desk. EasyEntra has completely transformed how we handle Microsoft 365 administration.”
Doug Sanders
Manager of Technical Customer Support, Junior Achievement USA, United States
“Your product is such a time saver. I love it!”
Scott Fehr
IT Infrastructure, MEC Aerial Work Platforms, United States
“It's a good product and saves us lots of time for these ongoing quick admin tasks.” 
Chris McFerran
Managing Director, CTech IT Solutions Ltd, United Kingdom
“EasyEntra has significantly streamlined our workflow, simplifying everything. It feels almost like a revolution.”
Johan Sadelius
IT-chef, Arjeplog Kommun, Sweden
I greatly appreciate your assistance and willingness to enhance the already outstanding product.”
Michael I. Wilson
Executive Director of Information Technology, Archdiocese Of Washington, United States
“It's great not having to switch back and forth between the O365 admin center and the Teams admin center to assign groups. I am sold!”
Thomas Madden
Director Information Technology, AutoPayPlus, United States
“I would highly recommend organizations use the solution as it greatly simplifies various tasks.”
S. Roger Singh
Chief Technology Officer, Prasad & Company LLP, Canada
“EasyEntra is time-saving. Love the copy/paste for user/computer groups and the copy to new user.”
Damian Nita
Associate Network Administrator, Shenandoah Valley Westminster-Canterbury, United States
“EasyEntra has transformed our daily IT operations by simplifying user management, reducing errors, and enhancing overall efficiency.”
Henrik Nefling
IT- and Digitalization Manager, Animal Protection Denmark, Denmark