如何从一个批处理文件来执行PowerShell命令? [英] How to execute powershell commands from a batch file?
问题描述
我有一个PowerShell脚本到一个网站在Internet Explorer中添加到受信任的站点:
I have a PowerShell script to add a website to a Trusted Sites in Internet Explorer:
set-location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set-location ZoneMap\Domains
new-item TESTSERVERNAME
set-location TESTSERVERNAME
new-itemproperty . -Name http -Value 2 -Type DWORD
我要执行从一个批处理文件,这些PowerShell命令。它似乎很简单,当我要运行一个命令, BUT 在这种情况下,我有相关的一系列命令。我想避免创造的PS脚本一个单独的文件,以从一批所谓的 - 一切都必须在批处理文件
I want to execute these PowerShell commands from a batch file. It seems simple when I have to run a single command, BUT in this case I have a sequence of related commands. I want to avoid creating a separate file for the PS script to be called from the batch - everything must be in the batch file.
现在的问题是:如何从一个批处理文件来执行PowerShell命令(或报表)
The question is: How to execute powershell commands (or statements) from a batch file?
推荐答案
这是code会是什么样子在一个批处理文件(测试工作):
This is what the code would look like in a batch file(tested, works):
powershell -Command "& {set-location 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'; set-location ZoneMap\Domains; new-item SERVERNAME; set-location SERVERNAME; new-itemproperty . -Name http -Value 2 -Type DWORD;}"
根据从信息:
<一个href=\"http://dmitrysotnikov.word$p$pss.com/2008/06/27/powershell-script-in-a-bat-file/\">http://dmitrysotnikov.word$p$pss.com/2008/06/27/powershell-script-in-a-bat-file/
这篇关于如何从一个批处理文件来执行PowerShell命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!