Solved

Powershell scheduled task error

Posted on 2013-06-12
4
2,884 Views
Last Modified: 2013-06-12
Hi Experts,

Am running two identical powershell scripts using task scheduler which take input from a .txt file and at scheduled times run the script. The second script runs successfully while the first seems to complete but I see the following in task result: "Incorrect function (0x800700001)". Also values do not get updated in the output so I know it is erroring out. Using administrator account to run the scripts so log on to run scripts is not an issue.

Script:
Import-Module ActiveDirectory
$USERS = Import-CSV c:\adupdate\cons\Updates_Cons.txt
$USERS|Foreach{Set-ADUSer -Identity $_.samaccountName -employeeNumber $_.EmployeeID -company $_.CompanyName -manager $_.Manager -Office $_.Location -department $_.Department -title $_.JobTitle -description $_.description}

In Task Scheduler I call it using a trigger of 1AM which starts a program powershell "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" with additional arguments: C:\adupdate\ADscriptCon.ps1

When I run the script manually using Powershell it updates information in AD without any issue. The second script is identical but updates info in another OU. Have deleted and recreated the script so not sure how to proceed.

TIA
0
Comment
Question by:abhijitm00
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
LesterClayton earned 500 total points
ID: 39240757
Why are you trying to run the 32 bit version of Powershell?

Try using C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe instead.

Also, be sure that the account you're running it as has sufficient AD permissions (the local administrator account on a member server for example, will not have sufficient AD permissions).  Also under security options check "Run whether user is logged on or not" and "Run with highest privileges" are both checked.

Also check that the account you are running it under has sufficient permissions to read c:\adupdate\cons\ folder.
0
 

Author Comment

by:abhijitm00
ID: 39240796
Hi Lester,

Thanks for getting back, I have changed the powershell location to new one pointed by you. The user running script is domain admin. Also confirmed that "Run whether user is logged on or not" and "Run with highest privileges" are both checked.

User has access to share. Reran script using task scheduler and got same error. Is there another way to call Powershell?
0
 
LVL 17

Expert Comment

by:LesterClayton
ID: 39240823
No, this is the only way to run Powershell commands - This is exactly the way I do it.  

I'm wondering if the problem isn't actually the script at all - or if you are having a generic problem with Task Scheduler.  Because the erorr "Incorrect function (0x800700001)" doesn't make sense

Can you create a simple script, something really really simple, and try to Task Schedule it, and see if you get the same issue?  The code should look something like this:

Write-Host "Hello World"

Open in new window


Save it as .ps1, then schedule it as a task.  If you get the same error then you may have an issue with Task Scheduler.  I would crack open the event logs and see if there is anything useful in there which might guide us.
0
 

Author Comment

by:abhijitm00
ID: 39241522
Lester, an update. The script had an incorrect path specified in the additional parameters which caused it to fail. The steps that you gave made me go back and check my stuff. Thanks for your help!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The reason that corporations and businesses use Windows servers is because it supports custom modifications to adapt to the business and what it needs. Most individual users won’t need such powerful options. Here I’ll explain how you can enable Wind…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now