Powershell script windows scheduling error
Hello,
Trying to schedule the powershell script to get the mailbox count on monthly bases. But when i schedule the script, it throws me an error in in the command prompt.
Powershell Script "c:\scripts\exch1.ps1"
$smtpServer = "server.testlab.local"
$smtpFrom = "mahess@testlab123.local"
$smtpTo = "jeevananthans@testlab.local"
$messageSubject = "TestLab Mailboxcount"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$con = Get-Mailbox | Group-Object -Property:ServerName | Select-Object
name,count | convertto-html
$message.Body = $con
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
Schedule Task Command:
C:\Scripts>Test.bat
C:\Scripts>powershell -command "& 'c:\scripts\exch1.ps1' "
Error Message:
C:\Scripts>powershell -command "& 'c:\scripts\exch1.ps1' "
The term 'Get-Mailbox' is not recognized as a cmdlet, function, operable progra
m, or script file. Verify the term and try again.
At C:\scripts\exch1.ps1:10 char:19
+ $con = Get-Mailbox <<<< | Group-Object -Property:ServerName | Select-Object
name,count | convertto-html
why this get-mailbox is not recognized, but in shell its running fine with out any error.
Regards
Jeevananthan SThanks& Regards Jeevananthan S
December 25th, 2011 12:43pm
You should point to Exchange cmdlets module.
In Exchange 2007 you should add proper file
PowerShell.exe -PSConsoleFile "C:\Program Files\Exchsrvr\Bin\ExShell.psc1" -Command ". 'c:\scripts\exch1.ps1'"
In Exchange 2010 you should add to the script cmdlet:
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010Regards, Konrad Sagala, MCT, MCSE+M, MCITP: Exchange 2007/2010
Free Windows Admin Tool Kit Click here and download it now
December 25th, 2011 4:12pm
Hi Konrad Sagala,
its working for me ...
ThanksThanks& Regards Jeevananthan S
December 25th, 2011 11:59pm