在隐藏窗口中从命令行运行PowerShell脚本

Dave P. said the comments of a previous post "...but it's ugly b/c it actually opens a command window to do it. Batch files don't have this issue. Now if you can figure out a way to run powershell scripts in a hidden window, then you'd be onto something."

Dave P.说了上一篇文章的评论“ ...但是它很丑,它实际上打开了一个命令窗口来执行它。批处理文件没有这个问题。现在,如果您能找到一种运行powershell的方法,脚本隐藏在一个隐藏的窗口中,那么您就会涉足其中。”

Running PowerShell Scripts from the command line is obscure and yucky to be clear, mostly because of escaping of quotes and such.

从命令行运行PowerShell脚本是晦涩难懂的,主要是因为转义了引号等。

If you want to run a hidden powershell script, you can use HStart from the awesomeness that is NTWind Software. (Just go over there and download all of his utilities and save yourself some time).

如果要运行隐藏的Powershell脚本,则可以使用NTWind Software的出色功能使用HStart 。 (只需到那里下载他的所有实用程序并节省一些时间即可)。

Here's how to run a hidden powershell script:

这是运行隐藏的Powershell脚本的方法:

hstart /nowindow "powershell.exe -command ""&" 'c:\DOCUME~1\Scott\desktop\foo.ps1'""

hstart / nowindow“ powershell.exe-命令”“&”'c:\ DOCUME〜1 \ Scott \ desktop \ foo.ps1'“”

If you're going to start running hidden scripts like this, or any script, make sure that you've got PowerShell transcripts started with start-transcript and stop-transcript.

如果要开始运行这样的隐藏脚本或任何脚本,请确保已将PowerShell脚本以start-transcriptstop-transcript开头

**********************
Windows PowerShell Transcript Start
Start time: 20070228113605
Username : MYDOMAIN\Scott
Machine : SUPERDUPERWONDERFUL-T60P (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is C:\Documents and Settings\Scott\My Docume
nts\WindowsPowerShell\Transcripts\20070228.113605.3196.txt

********************** Windows PowerShell笔录开始开始时间:20070228113605 用户名:MYDOMAIN \ Scott 机器:SUPERDUPERWONDERFUL-T60P(Microsoft Windows NT 5.1.2600 Service Pack 2) ********************** 字幕已启动,输出文件为C:\ Documents and Settings \ Scott \ My Docume nts \ WindowsPowerShell \ Transcripts \ 20070228.113605.3196.txt

GAC Version Location
--- ------- --------
False v1.1.4322 C:\Documents and Settings\Scott\My Documents\Window...
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

GAC版本位置--- ------- -------- False v1.1.4322 C:\ Documents and Settings \ Scott \ My Documents \ Window ... 设置使用Microsoft Visual Studio 2005 x86工具的环境。

True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0....

True v2.0.50727 C:\ WINDOWS \ assembly \ GAC_MSIL \ System.Windows.Forms \ 2.0 ....

Hey! I'm in powershell (this is my script running)
**********************
Windows PowerShell Transcript End
End time: 20070228113605
**********************

嘿! 我在Powershell中(这是我的脚本正在运行) ********************** Windows PowerShell笔录结束结束时间:20070228113605 **********************

You can make your scripts run faster by turning off the profile with the -noprofile switch, but be aware you'll have no profile and might not have some helper functions you've previously setup.

您可以通过使用-noprofile开关关闭配置文件来使脚本运行更快,但是请注意,您将没有配置文件,并且可能没有以前设置的帮助程序功能。

翻译自: https://www.hanselman.com/blog/running-powershell-scripts-from-the-command-line-in-a-hidden-window

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值