Active Directory Can't Parse Script? Here's the Real Fix
This error means AD hit a syntax error in a group policy logon/logoff script. The fix is finding and fixing that script. Here's how.
This error means one thing: a script you've linked to a GPO has a syntax error.
You're staring at the event log or a command that just vomited 0X0000218F back at you. It's annoying. Let's fix it fast.
The Fix: Hunt Down and Repair the Bad Script
What's actually happening here is the Directory Service tries to parse a script assigned to a user or computer logon, logoff, startup, or shutdown via Group Policy. The script file—usually a .bat, .vbs, or .ps1—has a syntax error. The error code DS_NTDSCRIPT_SYNTAX_ERROR confirms it.
- Open Group Policy Management Console (GPMC) on your Domain Controller. Right-click the domain and choose Search—this scans all GPOs. You can also browse manually if you know the scope.
- Search for scripts that are set to run. Look in Computer Configuration → Policies → Windows Settings → Scripts (Startup/Shutdown) and similarly under User Configuration → Logon/Logoff. Inspect each GPO that has a script assigned.
- Open the script file from its network path (usually
\domain\sysvol\…). Use Notepad or VS Code. Look for obvious errors—unclosed quotes, missing parentheses, or a stray%%in a batch file. If you're dealing with PowerShell, check for unclosed braces or missing parameters. - Fix the syntax error directly. Common culprits:
- Batch:
%variable%instead of%%variable%%insideforloops. - VBScript:
IfwithoutEnd IforSetwithoutNothing. - PowerShell: Missing
param()block or-instead of--.
- Batch:
- Test the script locally on a domain-joined machine with the same user context. Right-click and run it. If it fails, you've got the fix target.
- Run
gpupdate /forceon your DC and then check for the error again. If it's gone, you're done.
If you can't find the error quickly, just remove the script assignment from the GPO temporarily. Unlink the script under the same GPMC path, run gpupdate /force, and verify the error clears. That buys you time to debug the script without blocking logons.
Why Step 3 Works
The reason step 3 works is because the error isn't about network paths or permissions—it's strictly a parsing failure. AD reads the script content, tries to tokenize it, and chokes on invalid syntax. The script processor (cmd.exe for batch, WSH for VBS, PowerShell engine) throws this error when the parser can't build an AST. Fix the content, and the parse succeeds.
I've seen this most often with batch scripts that were edited on a Unix machine and picked up \r\n line endings—cmd.exe barfs on bare \n. Always save scripts with Windows-style CRLF line endings.
Less Common Variations
Sometimes the error shows up even when the script looks clean. Here's what else to check:
- Corrupt SYSVOL copy: If the script file is zero bytes or contains unprintable characters, the parser fails. Check file size in Explorer. Re-copy from a known-good backup.
- Encoding mismatch: PowerShell scripts saved as UTF-8 with BOM work fine; UTF-8 without BOM can break. Re-save the script with Notepad and choose UTF-8 with BOM.
- Linked GPO from another domain: If you're in a cross-forest trust scenario, the script path might resolve to a different domain's SYSVOL with different encoding. Verify the path in the GPO points to the correct FQDN.
- Third-party script engines: Some apps inject their own script processor (e.g., Kixtart, HTA). Check if the script requires a custom interpreter that's not available on the DC.
One more edge case: the error can fire during a repadmin /showreps or ntdsutil operation if a stale script reference exists in the NTDS database. Run repadmin /syncall /AdeP to force replication, then re-check the GPO.
Prevention
Stop editing scripts directly on the DC. Instead, keep your scripts in a version-controlled repo (Git), test them on a non-production VM with the same OS version, and only deploy via GPO after passing a syntax check. For PowerShell, use Invoke-Command -ScriptBlock { Test-ScriptFileInfo -Path $path } before assigning it. Use Group Policy Preferences to deploy scripts—they log errors more clearly.
Also, enable script error logging in Group Policy: under Computer Configuration → Administrative Templates → System → Scripts, enable Run logon scripts synchronously and Display error messages. That'll dump the exact line number next time.
If you're running Windows Server 2019 or 2022, know that the PowerShell engine is stricter about undefined variables in constrained language mode. I'd set up a test GPO with Set-ExecutionPolicy RemoteSigned and test scripts in that mode first.
That's it. Go fix that script and get back to your actual job.
Was this solution helpful?