I never had good luck getting scheduled tasks to run in the default
PowerShell console, 'cuz the console wants a "host" and Task Scheduler
doesn't provide one.
I ended up writing a custom host that basically just gets the results and
then does an out-string, which I can then either display in a web page or
redirect to a file.
Some sample C#:
sb.AppendLine("Command: " +
_txtCommand.Text);
sb.AppendLine();
foreach (PSObject ps in results)
{
sb.AppendLine(ps.ToString());
}
errorList = cmd.Error;
if (errorList.Count > 0)
{
sb.AppendLine();
sb.AppendLine("Error(s):");
sb.AppendLine();
foreach (object error in
errorList.ReadToEnd())
{
sb.AppendLine(error.ToString());
}
}
sb.AppendLine();
Regards,
Michael B. Smith
MCSE/Exchange MVP
http://TheEssentialExchange.com
From: Angie Urtel [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 26, 2008 1:55 PM
To: MS-Exchange Admin Issues
Subject: scheduled PowerShell task
I'd like to put this into Task Scheduler, but I can't seem to find the right
commands in order to run it from my workstation.
Saved as databases.ps1:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
get-mailbox -resultSize unlimited | ft DisplayName, Alias, Database >
"c:\temp\databases.txt"
Scheduled task:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command
"C:\temp\databases.ps1"
The error I get is "Active Directory server is not available. Supplied
credentials are invalid"
When I run it from the Exchange Shell, it works great. Only errors outside
of the Exchange Shell. What am I missing? This is the first time I've
tried scheduling PS output.
Thanks-
Angie
~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~ http://www.sunbeltsoftware.com/Ninja ~