Others

How to Fix PowerShell Script Failing with gMSA in Task Scheduler

Rana GarciaRana Garcia Oct 13, 2026 869 views

Question details

A PowerShell script running under a group Managed Service Account (gMSA) in Task Scheduler fails to create Azure AD shadow accounts.

How to Fix PowerShell Script Failing with gMSA in Task Scheduler
Product
Active Directory / Task Scheduler
Device & OS
not provided
Scenario
Automating user account creation by running a scheduled PowerShell script with a gMSA.
Observed behavior
The script works perfectly when run interactively but fails when triggered by Task Scheduler, even though the account has service logon and local administrator rights.
Before you start

Ensure you have Domain Administrator privileges to modify Organizational Unit (OU) security permissions in Active Directory before proceeding.

Solution 1Recommended

Grant gMSA Permissions on Active Directory Organizational Units

The gMSA requires explicit permissions to create and manage user objects within the specific OUs where the shadow accounts are being generated.

Local administrator rights and service logon privileges on the server are not sufficient for modifying Active Directory objects. The gMSA must be granted delegated permissions directly on the target Organizational Units.

1
Open Active Directory Users and Computers

Launch 'Active Directory Users and Computers' (ADUC) on your domain controller or through Remote Server Administration Tools (RSAT).

2
Enable Advanced Features

Click on the 'View' menu at the top and check 'Advanced Features' to reveal the Security tab for objects.

3
Access OU Security Properties

Right-click the target Organizational Unit (OU) where the accounts need to be created, select 'Properties', and navigate to the 'Security' tab.

4
Add the gMSA Account

Click 'Advanced', then 'Add'. Click 'Select a principal', search for your gMSA account (ensure 'Service Accounts' is checked in Object Types), and click 'OK'.

5
Assign Delegated Permissions

In the permission entry window, change 'Applies to' to 'Descendant User objects'. Check the boxes for 'Create User objects' and 'Delete User objects', then click 'OK' and 'Apply'.

Grant gMSA Permissions on Active Directory Organizational Units
Verify Task Execution: After updating the permissions, run the scheduled task again in Task Scheduler and review its execution history to confirm the user accounts are successfully created.
Free Microsoft Office alternative

Boost IT Productivity with WPS Office

While troubleshooting Windows Server and Active Directory environments, streamline your IT documentation, scripting logs, and reporting with WPS Office. It provides a lightweight, highly compatible alternative to Microsoft Office.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the Suite: Run the downloaded installer and follow the on-screen setup instructions.
  3. 3. Start Documenting: Launch WPS Office to easily open, edit, and save any Microsoft Office document.
Highly compatible with Microsoft Excel, Word, and PowerPoint formats (.xlsx, .docx, .pptx).Lightweight footprint ensures fast startup times on admin servers and workstations.Easily document Active Directory structures and PowerShell scripts with built-in templates.Free to use, reducing IT software licensing costs.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PowerShell script work interactively but fail in Task Scheduler?

Interactive sessions use your current logged-in user credentials, which often have higher Active Directory permissions (like Domain Admin rights). Task Scheduler runs as the assigned service account, which may lack specific AD permissions.

What is a Group Managed Service Account (gMSA)?

A gMSA is a special type of Active Directory account used for services and automated tasks. It provides automatic password management and simplified service principal name (SPN) management across multiple servers.

Do I need to assign 'Log on as a batch job' rights to my gMSA?

Yes. To run automated scripts in Windows Task Scheduler, the gMSA must be granted the 'Log on as a batch job' right via the local security policy of the machine executing the task.