windows - PowerShell 在命令提示符问题中, 'Format-Table' 未被识别为内部或外部命令、可运行程序或批处理文件

标签 windows powershell cmd command-prompt

我正在 cmd 中执行 powershell 脚本。

首先我写命令

C:\Windows\system32>启动 powershell.exe Set-ExecutionPolicy RemoteSigned

成功运行

比运行脚本我写命令

C:\Windows\system32>start powershell.exe C:\\Get-NetworkStatistics.ps1

它也能成功运行

问题是当我尝试运行该函数时

    C:\Windows\system32>start powershell.exe Get-NetworkStatistics -computername Gbsi1  | Format-Table -autosize

它给出错误“'Format-Table' 不被识别为内部或外部命令, 可运行的程序或批处理文件。”

这是它的截图。 enter image description here

它在powershell 中运行成功,但在cmd 中运行失败。管道有问题吗?我把它放在 Format-Table 之前

最佳答案

正如您所说,管道由 CMD 而非 powershell 解释。 因此,CMD 将尝试执行名为 Format-Table 的命令,该命令不存在(在 powershell 之外)。

您可以使用 ^ 转义它:

start powershell.exe Get-NetworkStatistics -computername Gbsi1 ^| Format-Table -autosize

或者引用完整的命令行

start powershell.exe "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"

请注意,您的调用无论如何都是错误的,您需要向 powershell 提供 -Command 选项,如下所示:

start powershell.exe -Command "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"

最后,你真的要使用start吗?它将打开一个新窗口,该窗口将在命令完成后立即关闭。您还可以使用:

powershell.exe -Command "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"

关于windows - PowerShell 在命令提示符问题中, 'Format-Table' 未被识别为内部或外部命令、可运行程序或批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159026/

相关文章:

用于svn删除文件夹集的windows批处理脚本

Powershell:如何在分配变量时摆脱 CMD 输出(nslookup)

powershell - 需要列出 IIS 6.0 (Server 2k3) 中的所有站点、应用程序池和子应用程序

powershell - 在Jenkins主节点和从节点之间共享文件

python - Windows 上的 Apache Zeppelin : error creating python interpreter

python-3.x - 导入错误 : DLL load failed while importing IfxPy on Windows with Python3. 8

powershell - 通过管道传递脚本 block

java - 如何在java程序中使用mkdir和rmdir命令

windows - Qt 在 Windows 8.1 上的安装

angularjs - 如何使用 npm install 解决隧道套接字错误?