Link to home
Start Free TrialLog in
Avatar of rawales2
rawales2Flag for United States of America

asked on

powershell script task in task manager won't stop

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.
Avatar of Qlemo
Qlemo
Flag of Germany image

Make sure you manually refresh the Task Scheduler display. It does often not reflect the actual state of tasks.
Avatar of rawales2

ASKER

Thanks, but I have been manually refreshing.
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The script is not expected to provide any feedback, so an empty box is ok.
Did you run as your user or as admin?
yes. it's all good.
Given credit to you for the -NoExit - that was really helpful.