Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

440
Visualizações
¿Cómo usar Where-Object en .NET PowerShell Automation?

Tengo esta canalización, que funciona en una consola de PowerShell:

 Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne 'Disconnected' }

Sin embargo, cuando lo intento en .NET usando System.Management.Automation falla con esta excepción:

 System.Management.Automation.CommandNotFoundException HResult=0x80131501 Message=The term 'Where-Object { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne 'Disconnected' }' 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. Source=System.Management.Automation StackTrace: at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at System.Management.Automation.Runspaces.Pipeline.Invoke() at Duplexer.PowerShell.Engine.ExecutePipeline(PSCommand Command) in D:\Dev\Projects\Duplexer\Duplexer\Code\PowerShell\Engine.vb:line 80 at Duplexer.Main.GetSettings() in D:\Dev\Projects\Duplexer\Duplexer\Main.vb:line 84 at Duplexer.Tests.PowerShellTests.Can_Get_NIC_Settings() in D:\Dev\Projects\Duplexer\Duplexer.Tests\PowerShellTests.vb:line 6

Aquí está mi código .NET:

 Public Sub GetSettings() Dim oPipeline As PSCommand Dim oResult As Collection(Of PSObject) oPipeline = New PSCommand oPipeline. AddCommand(PowerShell.Commands.GetNetIPConfiguration). AddCommand(PowerShell.Commands.WhereObject & " { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne 'Disconnected' }") Using oPowerShell As New PowerShell.Engine oPowerShell.ImportModules(PowerShell.Modules.NetAdapter, PowerShell.Modules.NetTCPIP) oResult = oPowerShell.ExecutePipeline(oPipeline) End Using End Sub

¿Cómo configuro este comando de PowerShell para usarlo en .NET Automation?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Debe proporcionar el argumento del parámetro (el scriptblock que sigue Where-Object ) por separado. Cambia esta línea:

 AddCommand(PowerShell.Commands.WhereObject & " { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne 'Disconnected' }")

a:

 AddCommand(PowerShell.Commands.WhereObject). AddArgument(ScriptBlock.Create("$_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -ne 'Disconnected'"))
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda