【发布时间】:2013-08-29 13:32:18
【问题描述】:
我正在寻找一种在命令提示符下仅运行几个 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 脚本。
-
并且
Get-AppLockerFileInformation在从新的干净的 powershell 提示符运行时对您来说效果很好?什么操作系统? (在 Win7 中测试了 Get-App.. 并且在这种情况下没有这样的 cmdlet,所以得到相同的错误消息) -
我首先使用
Import-Module AppLocker命令加载库。我正在使用 Windows Embedded 7。也许我需要结合 2 个调用,导入库然后运行命令...?? -
*.com/a/19111810 可能与您相关。它是关于如何将 .cmd 和 .ps1 组合成一个文件(.cmd)。
标签: powershell batch-file cmd