gpt4 book ai didi

powershell - 术语 ' ' 未被识别为 cmdlet 的名称

转载 作者:行者123 更新时间:2023-12-02 20:26:21 26 4
gpt4 key购买 nike

我正在尝试使用“运行”命令在一行中运行它:

powershell -NoExit ; Get-ChildItem -Recurse -force -Include *.ost \\PcHostname\c$\users -ErrorAction "SilentlyContinue" | ls | Select-Object Name, @{Name="GigaBytes";Expression={$_.Length / 1GB}}

但我收到此错误:

GigaBytes : The term 'GigaBytes' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:137
+ ... t Name, @{Name=GigaBytes;Expression={$_.Length / 1GB}}
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (GigaBytes:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

该代码可在启动的 Powershell 窗口上运行,无需 powershell -NoExit ;

有什么解决办法吗?

最佳答案

由于命令行参数通过“Run”标记化的方式,您需要转义 GigaBytes 周围的双引号(使用 \ 转义字符)或替换它们用单引号引起来。这两个 Select-Object 命令中的任何一个都应该有效:

Select-Object Name, @{Name=\"GigaBytes\";Expression={$_.Length / 1GB}}

Select-Object Name, @{Name='GigaBytes';Expression={$_.Length / 1GB}}

这是因为任何用双引号括起来的内容都将被解释为单个参数。

参见this回答有关如何通过“运行”对命令行参数进行标记的更详细说明。

关于powershell - 术语 ' ' 未被识别为 cmdlet 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24284469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com