Quantcast
Channel: Windows Server
Viewing all articles
Browse latest Browse all 26364

Powershell Task Scheduler question

$
0
0

Hey guys,

I am pulling my hair out on this one. I have a powershell script that i wrote that works perfectly when i run it manually or even from cmd.exe. I can get it to run multiple ways but i cannot get task scheduler to run it properly. I have tried several ways inside of task scheduler to do it but nothing works. Running Windows server 2008 and Exchange 2007

Here is the script:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

$DT = (Get-Date).AddDays(-7).ToString("d")

Get-Mailbox -identity myinbox | Export-mailbox -IncludeFolders "\Deleted Items" -StartDate "01/01/2013" -EndDate "$DT" -DeleteContent:$force -Confirm:$false

This is what i have under "action" in task scheduler:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\script\DeletedItemsPurge.ps1"

I have plugged that into a batch file as well. Ran the batch file and it worked perfectly. I know i have the commands right, but something is not functioning properly when i plug it into task scheduler. Any help would be appreciated!


Viewing all articles
Browse latest Browse all 26364

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>