Solved

Powershell scheduled task error

Posted on 2013-06-12
4
2,952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Understanding the various editions available is vital when you decide to purchase Windows Server 2012. You need to have a basic understanding of the features and limitations in each edition in order to make a well-informed decision that best suits y…
OfficeMate Freezes on login or does not load after login credentials are input.
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…

752 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