How to schedule a Powershell script??

J

jim

So i've got this nifty PowerShell script that needs to be scheduled to run
every day. I'm sure this is an incredibly easy question (forgive me, i'm a
"newbie"), but how the heck do i schedule it as an AT job? I can schedule
standard .BAT files no problem, but how do i tell the job to run in a
PowerShell envioronment? Does PowerShell have its own internal scheduling
mechanism?

If it matters, this is actually for the Exchange 2007 PowerShell.

Thanks in advance!
jim
 

My Computer

D

dreeschkind

"jim" wrote:

> I can schedule standard .BAT files no problem, but how do i tell the job to run in a
> PowerShell envioronment?


The easiest way is probably to put something like the following in your
batch file:
powershell.exe -command C:\do-foo.ps1 <script_parameter1> <script_parameter2>

Try "powershell -?" so see more command line options.

> Does PowerShell have its own internal scheduling
> mechanism?


Not yet, but afaik it is planned for one of the next major versions.

--
greetings
dreeschkind
 

My Computer

J

jim

I keep getting "powershell is not a valid command". Maybe it's the version
of Exchange i'm running. In any event, i figured out "A" way to do it
(probably not the most graceful, but it works for me).

"C:\Program Files\Microsoft Command Shell\v1.0\Msh.exe" -mshconsolefile
"C:\Program Files\Microsoft\Exchange Server\bin\exshell.mcf1" -command "&
'get-UserAttributes.msh' "



"dreeschkind" <[email protected]> wrote in message
news:[email protected]
> "jim" wrote:
>
>> I can schedule standard .BAT files no problem, but how do i tell the job
>> to run in a
>> PowerShell envioronment?

>
> The easiest way is probably to put something like the following in your
> batch file:
> powershell.exe -command C:\do-foo.ps1 <script_parameter1>
> <script_parameter2>
>
> Try "powershell -?" so see more command line options.
>
>> Does PowerShell have its own internal scheduling
>> mechanism?

>
> Not yet, but afaik it is planned for one of the next major versions.
>
> --
> greetings
> dreeschkind
 

My Computer

D

dreeschkind

"jim" wrote:

> I keep getting "powershell is not a valid command". Maybe it's the version
> of Exchange i'm running. In any event, i figured out "A" way to do it
> (probably not the most graceful, but it works for me).


Sorry, I missed the fact that you are using the Exchange shell. This one is
based on an older PowerShell release (it was called msh before). As you
figured out, you need to pass the (*.msh instead of *.ps1) script to the
script engine (in your case msh.exe instead of powershell.exe). However, I
expect the script engine of next release of the Exchange shell to be called
powershell.exe as well.

--
greetings
dreeschkind
 

My Computer

J

jim

I've heard that too.

"dreeschkind" <[email protected]> wrote in message
news:[email protected]
> "jim" wrote:
>
>> I keep getting "powershell is not a valid command". Maybe it's the
>> version
>> of Exchange i'm running. In any event, i figured out "A" way to do it
>> (probably not the most graceful, but it works for me).

>
> Sorry, I missed the fact that you are using the Exchange shell. This one
> is
> based on an older PowerShell release (it was called msh before). As you
> figured out, you need to pass the (*.msh instead of *.ps1) script to the
> script engine (in your case msh.exe instead of powershell.exe). However, I
> expect the script engine of next release of the Exchange shell to be
> called
> powershell.exe as well.
>
> --
> greetings
> dreeschkind
 

My Computer

I

IT Staff

assuming exchange powershell engine upgraded nex time, to run command script
locally at the exchange server, ie powershell -command <*.ps1> ...make sure
u do set-executionpolicy correctly , otherwise it won't run at command
prompt.




"jim" <[email protected]> wrote in message
news:[email protected]
> I've heard that too.
>
> "dreeschkind" <[email protected]> wrote in message
> news:[email protected]
>> "jim" wrote:
>>
>>> I keep getting "powershell is not a valid command". Maybe it's the
>>> version
>>> of Exchange i'm running. In any event, i figured out "A" way to do it
>>> (probably not the most graceful, but it works for me).

>>
>> Sorry, I missed the fact that you are using the Exchange shell. This one
>> is
>> based on an older PowerShell release (it was called msh before). As you
>> figured out, you need to pass the (*.msh instead of *.ps1) script to the
>> script engine (in your case msh.exe instead of powershell.exe). However,
>> I
>> expect the script engine of next release of the Exchange shell to be
>> called
>> powershell.exe as well.
>>
>> --
>> greetings
>> dreeschkind

>
>
 

My Computer

Top