Powershell: Command will not work with "powershell.exe -command "command"

Viewed 28

This Code will work:

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

I want start it from Taskscheduler (cmd) or in powershell This code will not work:

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

Error:

  • ... etAdapter | Where-Object {.InterfaceDescription -match 'Ethernet'-or ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (.InterfaceDescription:String) [Where-Object], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.WhereObjectCommand

Also as an base64 string same error.

Have anyone an idea why it will not work as an command but direct as command in ps?

thanks regards Bob

Sorry for my bad english.

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