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.
Microsoft DevelopmentPowershellWindows Server 2008

Avatar of undefined
Last Comment
rawales2
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
rawales2
Flag of United States of America image

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of rawales2
rawales2
Flag of United States of America image

ASKER

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
Avatar of rawales2
rawales2
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Qlemo
Qlemo
Flag of Germany image

The script is not expected to provide any feedback, so an empty box is ok.
Did you run as your user or as admin?
Avatar of rawales2
rawales2
Flag of United States of America image

ASKER

yes. it's all good.
Avatar of rawales2
rawales2
Flag of United States of America image

ASKER

Given credit to you for the -NoExit - that was really helpful.
Windows Server 2008
Windows Server 2008

Windows Server 2008 and Windows Server 2008 R2, based on the Microsoft Vista codebase, is the last 32-bit server operating system released by Microsoft. It has a number of versions, including including Foundation, Standard, Enterprise, Datacenter, Web, HPC Server, Itanium and Storage; new features included server core installation and Hyper-V.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo