[英]Run PowerShell command from command prompt (no ps1 script)
我正在寻找一种从命令提示符只运行几个 PowerShell 命令的方法。 我不想为此创建脚本,因为它只是我需要运行的几个命令,而且我真的不知道如何使用 PowerShell 编写脚本。
这是我尝试使用的命令:
Get-AppLockerFileInformation -Directory <folderpath> -Recurse -FileType <type>
我真的不想为此创建一个脚本,因为如果我可以从批处理文件中运行一两个命令和其余内容,那会容易得多。
编辑:这是我迄今为止尝试过的。
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.....}
这种方式没有错误,但我没有得到任何回报。 如果我使用Set-AppLockerPolicy...
没有任何反应。
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....}
没有错误,但没有任何反应。
7)
powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "Get-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}"
在单个命令行上运行它,如下所示:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile
-WindowStyle Hidden -Command "Get-AppLockerFileInformation -Directory <folderpath>
-Recurse -FileType <type>"
也许powershell -Command "Get-AppLockerFileInformation....."
看看powershell /?
这适用于我的 Windows 10 的 cmd.exe 提示符
powershell -ExecutionPolicy Bypass -Command "Import-Module C:\Users\william\ps1\TravelBook; Get-TravelBook Hawaii"
这个例子显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.