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?
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30)
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?
you can call a powershell script via task scheduler directly without the use of batch file.
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
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Get-Process "auto ftp manager" | Where StartTime -lt (Get-Date).AddMinutes(-30)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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.
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.
ASKER
Thank you Ryan Chong and oBdA very much for your assistance :)