我想要一个powershell脚本在后台每分钟运行一次。没有窗口可能出现。我该怎么做?在后台每分钟运行一次powershell脚本
回答
使用Windows任务调度和运行脚本是这样的:
powershell -File myScript.ps1 -WindowStyle Hidden
,它运行在一个特定的用户帐户和不仅当用户登录另外创建脚本。否则,你会看到一个控制台窗口。
也许这种情况下。我们不会每分钟都启动PowerShell可执行文件(这很贵,顺便说一下)。相反,我们通过调用一次每分钟调用一次工作脚本的额外脚本来启动它(或者在工作者脚本退出或失败后实际等待一分钟)。
创建开始调用-MyScript.ps1:
for(;;) {
try {
# invoke the worker script
C:\ROM\_110106_022745\MyScript.ps1
}
catch {
# do something with $_, log it, more likely
}
# wait for a minute
Start-Sleep 60
}
(从启动.bat文件如)从Cmd的运行如下命令:
start /min powershell -WindowStyle Hidden -Command C:\ROM\_110106_022745\Invoke-MyScript.ps1
出现PowerShell窗口片刻,但它由于start /min
而被最小化,并在一瞬间永久隐藏起来。所以实际上只有任务栏图标显示一会儿,而不是窗口本身。这不是太糟糕。
这些答案是很奇怪的! 如果你想运行PowerShell脚本作为后台作业尝试 启动工作。\文件夹中的脚本 从CLI你在内部脚本。
安排你的任务是运行的系统。下面的命令将安排一个脚本在后台运行,而不显示PowerShell控制台窗口:
schtasks /create /tn myTask /tr "powershell -NoLogo -WindowStyle hidden -file myScript.ps1" /sc minute /mo 1 /ru System
/ru
开关可以让你改变在计划任务将被执行的用户上下文。
谢谢Xemlock!在我的情况下,你的建议是唯一生成完全没有PowerShell窗口的解决方案。 – WebFixItMan 2017-03-10 19:46:27
在任务的任务计划程序属性的[常规]选项卡上,选择“运行用户是否已登录”单选按钮可防止窗口出现在我的Windows 7计算机上。
如果您想在时间间隔内自动运行脚本。 (对于Windows操作系统)
1) Open Schedule tasks from control panel.
2) Select Task Scheduler Library from left side window.
3) select Create Task from right side window.
4) Enter Name in General tab (any name).
5) Open Triggers tab -> New
6) Select interval as needed.Use Advanced settings for repeat task.
7) Open Actions tab ->New
8) Copy/Paste following line in Program/script *
* Here D:\B.ps1 in code is path to my B.ps1 file
C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \ powershell.exe d:\ B.ps1
9) ok and apply changes
10) Done!
# Filecheck.ps1
# Version 1.0
# Use this to simply test for the existance of an input file... Servers.txt.
# I want to then call another script if the input file exists where the
# servers.txt is neded to the other script.
#
$workpath=".\Server1\Restart_Test"
# Created a functon that I could call as part of a loop.
function Filecheck
{
if (test-path $workpath\servers.txt)
{
rename-item $workpath\servers.txt servers1.txt
"Servers.txt exist... invoking an instance of your script agains the list of servers"
Invoke-Expression .\your_Script.ps1
}
Else
{
"sleeping"
Start-Sleep -Seconds 60
}
}
Do
{
Filecheck
$fred=0
# Needed to set a variabe that I could check in the while loop.
# Probably a better way but this was my way.
}
While($fred -lt 1)
- 1. 每分钟运行一次PHP脚本
- 2. 每分钟运行脚本
- 3. 如何每5秒钟运行一次shell脚本2分钟?
- 4. 5分钟运行脚本一次(Linux)
- 5. 如何每N分钟在线运行一次Python脚本?
- 6. 如何在同一秒钟内每分钟运行一次脚本?
- 7. 如何每10分钟运行一次脚本
- 8. Cronjob每分钟运行多次同一个php脚本
- 9. 谷歌脚本:使脚本每分钟运行一次,但每天只运行一小时
- 10. 在后台每5分钟执行一次函数
- 11. 每10分钟在后台执行一次数据库操作
- 12. 每20分钟运行脚本
- 13. 每x分钟运行phantomjs脚本
- 14. 在Python运行PowerShell脚本,而不在每次运行
- 15. 每分钟运行一次的服务
- 16. 每x分钟运行一次代码
- 17. 如何每分钟运行一次AsyncTask?
- 18. Swift:每分钟运行一次func
- 19. 每245分钟运行一次cron
- 20. 一次在多台机器上运行PowerShell脚本列表
- 21. 每5分钟运行一次cronjob,但在第一次执行后停止?
- 22. 如何每15分钟执行一次后台任务?
- 23. 如何设置cron每40分钟/ 25分钟运行脚本?
- 24. 每分钟创建一次脚本只记录一次,但每秒运行一次
- 25. 在后台运行脚本?
- 26. 在后台运行脚本
- 27. android报警管理器每15分钟运行一次后台服务
- 28. 后台Powershell脚本
- 29. 每分钟执行一次shell脚本的crontab
- 30. crontab为什么每2分钟执行一次脚本?
你知道如何创建计划任务? – ghostdog74 2010-01-15 13:01:58