Avatar of Diane Burns
Diane Burns
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Cannot Run Disable-ADAccount as Scheduled Task on Server

I am trying to setup a powershell script to run as a scheduled task that disables an AD account every evening.

Disable-ADAccount -Identity <UserName>

The above script works when run manually, but not as a scheduled task.  So far I have tried running this under the System account on both the DC (server 2008 R2) and another member server (server 2012 R2) but although they say "Task Completed" in the history, the account remains enabled.  To clarify, the settings are here GeneralActions
I have also tried running it as myself, but get the error that I need "Log on as batch right" permissions

So my question is what do I need to do to get this working?  And is it better to run it from the DC or the other server?

Thanks for your help
Powershell* task scheduler

Avatar of undefined
Last Comment
Diane Burns

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Diane Burns

ASKER
Brilliant thank you that works!

For anyone reading this who needs to know the exact procedure, I used Delegation Wizard in AD to give the server account permissions to "create, delete and manage user accounts" on the OU containing the user account.

Thanks for pointing me in the right direction!
Diane Burns

ASKER
this method worked
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck