Solved

Powershell scheduled task error

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article will review the basic installation and configuration for Windows Software Update Services (WSUS) in a Windows 2012 R2 environment.  WSUS is a Microsoft tool that allows administrators to manage and control updates to be approved and ins…
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…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
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 …

623 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