从命令提示符运行PowerShell命令(无ps1脚本) [英] Run PowerShell command from command prompt (no ps1 script)
问题描述
我正在寻找一种方法,从命令提示符下运行几个PowerShell命令。我不想为此创建一个脚本,因为它只是一个需要运行的几个命令,因为我真的不知道如何用PowerShell脚本。
这里是我尝试使用的命令开始:
Get-AppLockerFileInformation -Directory< folderpath> -Recurse -FileType< type>
我真的不想为此创建一个脚本,只需从批处理文件中运行一个或两个命令与其余的东西。
编辑:
这是我到目前为止的尝试。 p>
1)
powershell -CommandGet-AppLockerFileInformation .... 。
错误:术语'Get-AppLockerFileInformation'不被识别为cmdlet,函数,脚本文件或可操作的程序的名称....
2)
powershell -Command {Get-AppLockerFileInformation ...}
没有错误,但我没有回来。如果我使用 Set-AppLockerPolicy ...
没有任何反应。
3)
powershell -Command{Get-AppLockerFileInformation .....}
错误:术语'Get-AppLockerFileInformation'一个cmdlet,函数,脚本文件或可操作的程序....
4)
powershell -Command& {Get-AppLockerFileInformation .....}
错误:术语'Get-AppLockerFileInformation不被识别为cmdlet,函数,脚本文件或可操作的程序的名称....
5)
powershell& {Get-AppLockerFileInformation .....}
错误: 'get-AppLockerFileInformation未被识别为cmdlet,函数,脚本文件或可操作的程序的名称。
6)
powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command {Get-AppLockerFileInformation ....}
没有错误,但没有任何反应。
7)
powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -CommandGet-AppLockerFileInformation ....
没有错误,但没有任何反应。
解决方案以下是唯一的答案,可以解决我的问题,借助此网页(不错的参考)。
powershell -command& {&'some-command'someParam}
命令:
powershell -command& {&'some-command'someParam};& {&'some-command'-SpecificArg someParam}
例如,我的2个命令:
powershell -command& {&'Import-Module'AppLocker};& {&'Set-AppLockerPolicy'-XmlPolicy myXmlFilePath.xml}
I'm looking for a way to run just a couple PowerShell commands from the command prompt. I don't want to create a script for this since it's just a couple commands I need to run and since I don't really know how to script with PowerShell.
Here is the command I'm trying to use to start with:
Get-AppLockerFileInformation -Directory <folderpath> -Recurse -FileType <type>
I don't really want to create a script for this as it would be much easier if I can just run one or two commands from a batch file with the rest of the stuff.
EDIT: Here is what I've tried so far.
1)
powershell -Command "Get-AppLockerFileInformation....." Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
2)
powershell -Command {Get-AppLockerFileInformation.....}
No error with this way but I don't get anything back. If I use the
Set-AppLockerPolicy...
nothing happens.3)
powershell -Command "{Get-AppLockerFileInformation.....}" Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
4)
powershell -Command "& {Get-AppLockerFileInformation.....}" Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
5)
powershell "& {Get-AppLockerFileInformation.....}" Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....
6)
powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command {Get-AppLockerFileInformation....}
No error but nothing happens.
7)
powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "Get-AppLockerFileInformation...."
No error but nothing happens.
解决方案Here is the only answer that managed to work for my problem, got it figured out with the help of this webpage (nice reference).
powershell -command "& {&'some-command' someParam}"
Also, here is a neat way to do multiple commands:
powershell -command "& {&'some-command' someParam}"; "& {&'some-command' -SpecificArg someParam}"
For example, this is how I ran my 2 commands:
powershell -command "& {&'Import-Module' AppLocker}"; "& {&'Set-AppLockerPolicy' -XmlPolicy myXmlFilePath.xml}"
这篇关于从命令提示符运行PowerShell命令(无ps1脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文