Link to home
Start Free TrialLog in
Avatar of Attila Mosonyi
Attila Mosonyi

asked on

How to run a poweshell command from a batch file

I would like to run a powershell command:
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30) | Stop-Process -Force
every 12 hours on a server automatically.
I was thinking to use a batch file and windows scheduler to run it.
How do I make the powershell command run from a batch file?
Is there a better solution to achieving this task, i.e. running the ps command automatically every 12 hours?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you can call a powershell script via task scheduler directly without the use of batch file.
Avatar of Attila Mosonyi
Attila Mosonyi

ASKER

Hi Ryan, I need help with creating the powershell script for:
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30) | Stop-Process -Force
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As I mentioned before, I don't have any experience/knowledge with powershell, so please someone help me with creating a script (.ps1) for the following:
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30) | Stop-Process -Force
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Putting the commandlet simply into a *.ps1 doesn't do the job.
I tested it by simply running it manually. It only completes the job, when the powershell is running in elevated mode, i.e. as administrator. So how do I put this in the *.ps1?
Again the same as in batch/cmd.exe (or any other program that requires elevation); you start a PS console by right-clicking the shortcut and select "Run as Administrator", and run the script from there.
When scheduling the task, you have a checkbox option "Run with highest privileges", or you just use the System account to run the task under.
Thank you Ryan Chong and oBdA very much for your assistance :)