如何在不显示窗口的情况下将Powershell脚本作为后台任务运行? [英] How can I run a powershell script as a background task without displaying a window?

查看:544
本文介绍了如何在不显示窗口的情况下将Powershell脚本作为后台任务运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个脚本,该脚本将触发性能计数器并将其存储在.csv文件中,并在文件太大时进行翻转.从powershell提示符或ISE(我正在运行v.2/win server 2008)运行脚本可以正常工作,并且文件运行正常.

I'm working on creating a script that will fire off performance counters and store them in a .csv file, rolling over when the file gets too big. Running the script from a powershell prompt or the ISE (I'm running v.2/win server 2008) works just fine, and the files are running correctly.

但是,当我尝试使用以下cmd提示符行执行命令时(即使尝试在cmd上使用/k开关),命令提示符也会立即关闭,并且文件无法运行.

However, when I try to execute the command using the following cmd prompt line (even trying the /k switch on cmd), the command prompt closes immediately and the file is not getting run.

powershell.exe -windowstyle hidden {iis_test.ps1}

我也尝试了以下方法,尽管我看到Powershell并没有停止(我通过任务管理器对其进行监视,以寻找要显示的Powershell.exe),但是我没有看到正在创建的文件.

I've also tried the following, and although I see Powershell doesn't stop (I monitor it via task manager, looking for Powershell.exe to show up), I'm not seeing the file being created.

powershell.exe -noexit -windowstyle hidden {iis_test.ps1}

我也没有看到在任何可能的位置(事件查看器,命令提示符窗口本身)捕获任何错误.

Nor am I seeing any errors being caught in any of the likely places (event viewer, the command prompt window itself).

有什么想法吗?最终,我的目标是让vb winforms调用这些脚本文件,自然地,我认为弄清楚命令提示符命令会有所帮助. 请注意,此脚本可移植并且可以在任何Windows 2008 Server系统上运行非常重要(因此,我需要远离需要进一步安装的第三方实体).

Any ideas? Ultimately, my goal is to have a vb winforms thing call these script files, and naturally I thought figuring out the command prompt command would be helpful. Note that it is very important that this script be portable, and run on any Windows 2008 Server system (so I need to stay away from third party entities that would require further installation).

编辑:我需要使用-file参数指定要运行的文件.

I needed to use the -file argument to specify a file to run.

推荐答案

从DOS/CMD shell尝试此操作:

try this from a DOS/CMD shell:

powershell.exe -windowstyle hidden -file C:\iis_test.ps1

这篇关于如何在不显示窗口的情况下将Powershell脚本作为后台任务运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆