Question : Server 2008/Exchange 2010 Scheduled Task: Exchange Shell Script Not working

I have a scheduled task setup to run once a month that use a script to get Mail Box information and push it out to a CSV file on a network share for reporting.

The Script executes correctly inside Power Shell, however when the task runs it simply Opens Notepad and display the script syntax.

Here is the script:

Get-MailboxStatistics -Server SERVERNAME | select-object DisplayName,TotalItemSize,ItemCount,StorageLimitStatus | export-Csv "T:\Rockbridge Network Documentation\50 Reporting\Email & Archiving\Monthly CSV File\data.csv"

Any idea  why this works correctly when ran inside the shell but doesn't run at all when called from outside?

Answer : Server 2008/Exchange 2010 Scheduled Task: Exchange Shell Script Not working

I switched the order of ' and " and now it seems to work:

-command "New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourexchangeserverFQDN/PowerShell/ -Authentication Kerberos; $s = Get-PSSession; Import-PSSession -Session $s; Get-MailboxStatistics -Server SERVERNAME | select-object DisplayName,TotalItemSize,ItemCount,StorageLimitStatus | export-Csv 'T:\Rockbridge Network Documentation\50 Reporting\Email & Archiving\Monthly CSV File\data.csv'"

If it still does not work then try put the full path for the program:
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Random Solutions  
 
programming4us programming4us