Powershell commands won't run in Task Scheduler

On a Windows 2008 R2 member server (Win 2003 domain), I can run a batch file like this on command line:

"powershell.exe -noexit -noprofile -executionpolicy Unrestricted -file C:\Bin\Scripts\BitsTransfer-Server05.ps1"

However, the batch file fails as a scheduled task, with following error:

"Start-BitsTransfer : The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist."

The job is scheduled under a service account which is a member of Domain Admin group. And, yes, I have checked "Run whether user is logged on or not" and "run with highest privileges". Logging on as that account to the server did not make a difference.

I am able to run the scheduled jobs on other servers with the same account and same configuration without a problem. Thanks for any help.

Jay Kulsh

 

June 5th, 2012 7:24am

This post might help you a bit in the right direction:
http://social.technet.microsoft.com/Forums/eu/winserverpowershell/thread/1464860b-db04-4e2e-8788-b789c6649e5b

Maybe on that one server the System Event Notification Service (SENS) is not receiving user logon notifications.

Free Windows Admin Tool Kit Click here and download it now
June 5th, 2012 11:59am

Hi,

In addition, please also refer to the below thread regarding to schedule Powershell script tasks:

Scheduled Task in Powershell

http://social.technet.microsoft.com/Forums/en-IE/exchange2010/thread/c1ea6f2c-5e37-4ab9-9dcc-c649be832e9c

How to schedule a powershell script through Schedule tasks

http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/0cad57bf-1113-4622-aac3-c3278fa97d72

Regards,

Yan Li

June 6th, 2012 5:19am

HicanNL,

I was so hopeful after seeing your link, but instructions there are quite incomplete and/or non-applicable, and the problem remains.

The link advised to start the BITS service under administrator account (rather than Local System), but when I specified an admin account, the service would not start giving "Error 1079: The account specified for this service is different from the account specified for other service running in the same process."

How may I know what other service is running in the same process? Again, based on that link, I assumed it is System Event Notification Service (SENS) and I specified an admin account there but that too gave Error 1079 when I tried to start the service.

So I had to revert both services back to Local System logon.

Let me add that my initial error also says this:

(Exception from HRESULT: 0x800704DD) At C:\Bin\Scripts\BitsTransfer-AlbacoreProEdata-Diff.ps1:29 char:19
+ Start-BitsTransfer <<<<  `    + CategoryInfo          : NotSpecified:

Thanks.

Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 10:28am

Yan Li,

You are suggesting some good links but they are really not applicable in this case.

JK

June 6th, 2012 10:30am

you can use something like process explorer to see what is running under it to change it.   so you logged in as the service account and ran the script with at least the -noprofile and that worked fine? its just when its a scheduled task?    
Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 2:20pm

It would be helpful if you could post the contents of "BitsTransfer-Server05.ps1" for analysis.
June 6th, 2012 5:52pm

Zeaun,

I am running the script shown on this link:

http://blogs.technet.com/b/ashleymcglone/archive/2010/11/18/big-downloads-with-powershell.aspx  

Have changed only source and destination to something like:

$src  = "\\RemoteServer\F$\BKUP\FullProE.bkf"                     
$dest = "C:\Backups\remoteBKUPs\"            

Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 7:02pm

jrich,

Thanks for suggesting Process Explorer.

The BITS service runs as "svchost.exe -k netsvcs". I found its PID and Process Explorer showed that 11 services (including SENS) run in that process. I am not planning to change logon for those services ;-/

About your 2nd suggestion, yes I can logon as that user account and run that batch file without '-noprofile' from command prompt, but not within Task Scheduler.

June 6th, 2012 7:27pm

You might be able to resolve this by storing the credentials with the script.  Here's a snippet I like to use to store script credentials:

$credential = Get-Credential
$credential.Password  | ConvertFrom-SecureString | Set-Content cred.pwd

You can then extract those credentials for use in your script.

I would also try removing the "-noprofile" argument.

Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 9:09pm

Zeaun,

Removing "-noprofile" made no difference.

I added those 2 lines to the script. But how do I provide credentials within the script? Thanks.

June 6th, 2012 11:00pm

HicanNL,

I was so hopeful after seeing your link, but instructions there are quite incomplete and/or non-applicable, and the problem remains.

The link advised to start the BITS service under administrator account (rather than Local System), but when I specified an admin account, the service would not start giving "Error 1079: The account specified for this service is different from the account specified for other service running in the same process."

How may I know what other service is running in the same process? Again, based on that link, I assumed it is System Event Notification Service (SENS) and I specified an admin account there but that too gave Error 1079 when I tried to start the service.

So I had to revert both services back to Local System logon.

Let me add that my initial error also says this:

(Exception from HRESULT: 0x800704DD) At C:\Bin\Scripts\BitsTransfer-AlbacoreProEdata-Diff.ps1:29 char:19
+ Start-BitsTransfer <<<<  `    + CategoryInfo          : NotSpecified:

T

Free Windows Admin Tool Kit Click here and download it now
June 7th, 2012 1:18pm

Hican,

First of all, thanks for sticking with me.

We not only have to worry about dependencies of BITS service, we also need to look at what other services are running in that process due to Error 1079: "The account specified for this service is different from the account specified for other service running in the same process."

I found 14 other services running in that process:

Application Information
Application Management
Certificate Propagation
Group Policy Client
IKE and AuthIP IPsec Keying Modules
IP Helper
LANMANserver
User Profile Service
Task Scheduler
System Event Notification (*)
Remote Desktop Configuration
Shell Hardware Detection
Windows Management Instrumentation
Windows Update

(*) System Event Notification Service is common to both sets.

I am extremely reluctant to change Logon accounts for all these 20 services, as that might have undesired consequences -- unless a Microsoft article tells me to do so. There ought to be a better way... Thanks again.

June 7th, 2012 5:53pm

I am extremely reluctant to change Logon accounts for all these 20 services, as that might have undesired consequences -- unless a Microsoft article tells me to do so. There ought to be a better way... Thanks again
Free Windows Admin Tool Kit Click here and download it now
June 8th, 2012 8:08am

Unfortunately, this posting of Friday, June 08, 2012 8:08 AM was NOT a solution for me. Thanks.
June 14th, 2012 1:43am

Do you have a Powershell profile script?  I believe they're always stored in My Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1.  If you do, try removing or renaming it.

I had a similar problem where scheduled jobs wouldn't run, and found out that even if you set your execution policies to Unrestricted, *and* run your scheduled job with the '-executionpolicy bypass' argument, when you launch powershell.exe it stops execution and prompts you about whether you want to run the profile or not.  I couldn't find a workaround for that except to run the job under an account that has no profile.

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 3:08pm

Scott,

Thanks for posting your solution. However, in my case, there are no PS profiles.

July 10th, 2012 4:54am

Did you disable UAC? I just tested, what I suggested in my previous post, on a clean VM and it works! Seems like you have some other issue running. Could you also try this on a clean machine / VM in your environment and see what it does?
Free Windows Admin Tool Kit Click here and download it now
July 10th, 2012 7:02am

Jay

Although you may have already found a resolution to your issue, I'm still going to post this note to benefit someone else. I ran into a similar issue.

I basically used a different domain account to test and the task ran just fine. A couple of things to keep in mind and make sure of:

1. The account being use to execute task must have "Logon as batch job" rights under the local security policy of the server. You must specified the account you need to run scripts/bat files.

2. Make sure you are entering the correct password characters

3. Tasks in 2008 R2 don't run interactively specially if you run them as "Run whether user is logged on or not". This will likely fail specially if on the script you are looking for any objects\resource specific to a user-profile when the task was created as the powershell session will need that info to start, otherwise it will start and immediately end.

Example for $Path:

mapped drive (\\server\share) x:\   vs.  Actual UNC path \\server\share

4. Review your steps, script, arguments. Sometimes the smallest piece can make a big difference even if you have done this process many times. I have missed several times a character on the password or a semi-colon sometimes.

Check the link provided and hopefully you or someone else can benefit from this info. Be safe.

https://technet.microsoft.com/en-us/library/cc722152.aspx


April 6th, 2015 2:55pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics