Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell scheduled task error

Posted on 2013-06-12
4
Medium Priority
?
3,025 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 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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

The following article is comprised of the pearls we have garnered deploying virtualization solutions since Virtual Server 2005 and subsequent 2008 RTM+ Hyper-V in standalone and clustered environments.
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…
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 restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.

705 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