PowerShell:命令不能与“Powershell.exe-Command”命令一起使用“

f45qwnt8  于 2022-11-10  发布在  Shell
关注(0)|答案(1)|浏览(119)

此代码将起作用:

Get-NetAdapter | Where-Object {$_.InterfaceDescription -match 'Ethernet' -or $_.InterfaceDescription -match 'Wireless'}

我希望从TaskScheduler(Cmd)启动它,否则在PowerShell中此代码将无法工作:

Powershell.exe -Command "Get-NetAdapter | Where-Object {$_.InterfaceDescription -match 'Ethernet' -or $_.InterfaceDescription -match 'Wireless'}"

错误:

  • ..EtAdapter|WHERE-Object{.InterfaceDescription-Match‘EtherNet’-或...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo:ObjectNotFound:(.InterfaceDescription:字符串)[Where-Object],CommandNotFoundException
  • FullyQualifiedError ID:CommandNotFoundException,Microsoft.PowerShell.Commands.WhereObjectCommand

同样作为Base64字符串,也会出现相同的错误。
有没有人知道为什么在PS中它不是作为命令而是直接作为命令工作的?

bxjv4tth

bxjv4tth1#

Powershell.exe -Command "Get-NetAdapter ; Where-Object {$_.InterfaceDescription -match 'Ethernet' -or $_.InterfaceDescription -match 'Wireless'}"

相关问题