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
Diane BurnsIT Support AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
Why would the computer account running the script have rights to disable the user account? Have you granted the server account rights to disable the user?

You'll have a slight challenge that the task scheduler works on exit codes, and PowerShell whether the command works or not, will not be returning an exit code like that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Diane BurnsIT Support AnalystAuthor Commented:
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!
0
Diane BurnsIT Support AnalystAuthor Commented:
this method worked
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.