Problem in Exchange 2007 Powershell Schedule Task to run
Hi Team Currently am struggling with Exchange 2007 powershell schedule task i have a powershell script which will create HTML fiile to find the current Active Node in CCR The Script is working fine and creating the HTML file without any issue. so, i am thinking of to put the script in schedule task to run the PS1 script for each 1 Hour. the HTML file report which is having the current time and date in that created a bat file PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command ". 'D:\ramki\clusteractivemon.ps1'" Whenever the task runs, it is not creating the HTML file , but when i run the bat manaully by duble clicking, the HTML files created with correct time and date. Say for example. Scripts scheduled by 9.00 AM to start by 10AM Task ran at 10.00AM but no HTML created at 10.00 AM but when i manually double click the BAT file by 10.10 or any time, HTML file is created without any issue i had created in Task Schedular in Windows 2008 server ---> created a basic task I wonder , why my scripit is not working in Schedule task. Could any one please help me Appreciate your fast response ramakrishnan
May 19th, 2012 4:56am

Is this literally saved as a .bat file? You can save it with the extension .ps1 Otherwise, here's a thread that might be useful: http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/0cad57bf-1113-4622-aac3-c3278fa97d72 * Looks like there's a couple ways to make this happen. Why don't you try this syntax: * powershell.exe "& 'C:\ProgramData\Microsoft\Windows NT\MSFax\ActivityLog\ParseOutbox.ps1'" Pay attention to the quotes. I've also seen this suggested (single quotes only): * powershell.exe & 'c:\path\to\script\FileName.ps1' Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2012 6:05am

HI Thanks What i did was .... Craeted a notepad file and copy the below and saved as test.bat file . Saved it in my D: drive (Location : D:\Ramki\Clumon.bat) PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command ". 'D:\ramki\clusteractivemon.ps1'" then gone to schedule task and craeted the basic task -->Action Menu -->Start a program selected the test.bat file to run also i tried to open the .PS1 file to run directly via basic task -->Action Menu -->Start a program selected the clusteractivemon.ps1' file to run it opens the .PS1 file in notepad am i doing anything wrong ramakrishnan
May 19th, 2012 6:42am

Hi, I don't understand the need to create a bat file. Why not just call your Powershell script directly? Just copy the hole string to Program/Script when you create the Task. One more thing...are you running the script with a user account or SYSTEM? Test with System if you're not using it.Martina Miskovic
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2012 7:02am

Hi Martina You mean to say that i need need to copy the below command in action menu to run the PS1 Directly. PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command ". 'D:\ramki\clusteractivemon.ps1'" if am wrong any steps to add the PS1 in task please ramakrishnan
May 19th, 2012 12:06pm

Hi, If you create a Basic Task (as you mentioned you were) you can copy the hole sting in Program/Script. You will then get a dialog box asking if you want to run powershell.exe with arguments. Yes should be the answer to that question. If you instead choose to create a new Task (not using the Basic Task Wizard) add powershell.exe to Action and the rest (-PSConsole etc) as an argument.Martina Miskovic
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2012 12:52pm

Hi No Luck still Once i did run the task as per the above , the task runs but not creating the output file (HTML file) from the PS1 Basically, whenever the script (PS1) runs from the powershell command it will create a HTML file with current date and time but when i put the same script in the schedeule task it won't create the HTML file ramakrishnan
May 19th, 2012 2:10pm

One more thing...are you running the script with a user account or SYSTEM? Test with System if you're not using it. Martina Miskovic What is the answer to my question?Martina Miskovic
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2012 2:33pm

On Sat, 19 May 2012 08:48:16 +0000, rush2ramki wrote: > > >Hi Team > >Currently am struggling with Exchange 2007 powershell schedule task > >i have a powershell script which will create HTML fiile to find the current Active Node in CCR > >The Script is working fine and creating the HTML file without any issue. > >so, i am thinking of to put the script in schedule task to run the PS1 script for each 1 Hour. the HTML file report which is having the current time and date in that >created a bat file > >PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command ". 'D:\ramki\clusteractivemon.ps1'" > >Whenever the task runs, it is not creating the HTML file , but when i run the bat manaully by duble clicking, the HTML files created with correct time and date. > >Say for example. Scripts scheduled by 9.00 AM to start by 10AM > >Task ran at 10.00AM but no HTML created at 10.00 AM > >but when i manually double click the BAT file by 10.10 or any time, HTML file is created without any issue > >i had created in Task Schedular in Windows 2008 server ---> created a basic task > >I wonder , why my scripit is not working in Schedule task. > >Could any one please help me > >Appreciate your fast response Does your scheduled task run with the same credentials, or credentials that have sufficient permission to write to the directory? Does your script do any sort of error checking/reporting when something you expect to work doesn't? Are you sure your script is even running? If you want to run that script from a .bat file, try this in the .bat file: PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command "& {D:\ramki\clusteractivemon.ps1}" --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
May 19th, 2012 5:45pm

Hello All Thanks for all inputs My problem got resolved by adding the location of the outputfile in the script file and also i created a .CMD file with the below deatils @echo off Powershell -command "& { D:\Ramki\ClusterActivemon.ps1 }" Created the schedule task in the action menu with .CMD file All Looks good now Thanks to all and learned a lot ramakrishnan
Free Windows Admin Tool Kit Click here and download it now
May 20th, 2012 5:14am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics