Solved

Powershell scheduled task error

Posted on 2013-06-12
4
2,912 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 18

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 18

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Table of Contents: Lesson 1 - Installing Windows Server 2012 (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2012/A_11592-Become-an-Administrator-Installing-Windows-Server-2012.html) Lesson 2 - Configuring Ser…
Every now and then, Microsoft does something that totally impresses me. It doesn't happen often, but in this case I must say I am thoroughly impressed with Windows Server Backup. One of the long time issues with Windows Backup has been the ability t…
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

777 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