[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

powershell script task in task manager won't stop

Posted on 2014-12-18
8
Medium Priority
?
552 Views
Last Modified: 2014-12-23
I have a powershell script that I am trying to run from task scheduler. The script looks in the ou "domain user accounts" for the extensionAttribute1 value and then exports the list to a csv. The script works fine when executed from powershell but when running it from task scheduler it never finishes running. The exported csv is created however.

Here is the script-
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

$OU='OU=domain user accounts,DC=domain,DC=local'
$ext14='mf7_6'
Get-Mailbox -OrganizationalUnit $OU|
Where {($_.customAttribute1 -eq $ext14)} | export-csv c:\userstest.txt

Open in new window


The task is running as domain\administrator with highest privileges.
It is set to run powershell with the arguments-
-ExecutionPolicy Bypass c:\scripts\exportOWA.ps1

Thanks in advance.
0
Comment
Question by:rawales2
[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
  • 5
  • 3
8 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 40507427
Make sure you manually refresh the Task Scheduler display. It does often not reflect the actual state of tasks.
0
 

Author Comment

by:rawales2
ID: 40507461
Thanks, but I have been manually refreshing.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 1500 total points
ID: 40507553
Don't see any reason for that, so you'll need to check several things. I'll assume you are running the task on the same machine as you have run the script manually.

Run the task with your own account, and by adding -NoExit as first switch  - if the script runs and finishs, you should have a powershell prompt now without errors. Close it, and rollback the changes made.

Add another command creating a file to the script, like  dir | export-csv c:\dir.txt, and see if that file is created too.
Is the PowerShell process visible in Task Manager after the task should have finished?

Did you check the task's log?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:rawales2
ID: 40507706
ok. when I add the no exit argument it just brings up powershell with a prompt... I've also tried -NoExit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\Scripts\exportOWAps1"

This loads the exchange tools and connects to my exchange server but then just sits..
0
 

Accepted Solution

by:
rawales2 earned 0 total points
ID: 40507730
ok. Changed the arguments to
-NoExit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; .  c:\Scripts\exportOWA.ps1"

Open in new window


and it's working now. Apparently you need to connect to the exchange server first even though it's being run on the exchange server. Makes sense.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40507736
The script is not expected to provide any feedback, so an empty box is ok.
Did you run as your user or as admin?
0
 

Author Comment

by:rawales2
ID: 40507766
yes. it's all good.
0
 

Author Closing Comment

by:rawales2
ID: 40514607
Given credit to you for the -NoExit - that was really helpful.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

650 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