Strange Powershell 5.0 behaviour

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 1 year, 9 months ago.

  • Author
    Posts
  • #28235
    Profile photo of Tobias
    Tobias
    Participant


    $NICs = Get-WmiObject Win32_NetworkAdapter | Where-Object {$_.PhysicalAdapter -eq $true}

    $NICs | Select-Object Name, DeviceID

    $NICnumber = Read-Host "`nSelect Network Adapter"

    When running the code above on PowerShell 4.0 it works normally, but when I try it on Powershell 5.0 the list of network cards isn't displayed. Somehow Read-Host screws up the output, I also get the same result with "[Console]::ReadLine()". Is this a bug or what?

  • #28236
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    I can't reproduce your problem. Running your code on PowerShell 5 on Windows 10 RTM works for me

  • #28237
    Profile photo of Tobias
    Tobias
    Participant

    Strange, I got the same result on two different Machines.

  • #28238
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    I can reproduce it on Win10 RTM. The output of the Select-Object gets displayed after the Read-Host prompt instead of before.

    You should submit a bug report via Connect – http://connect.microsoft.com/powershell.

    A workaround would be to use Format-Table to get the correct output.


    $NICs = Get-WmiObject -Class Win32_NetworkAdapter |
    Where-Object { $_.PhysicalAdapter -eq $true }

    $NICs | Format-Table -Property DeviceID, Name

    $NICNumber = Read-Host "`nSelect Network Adapter"

  • #28241
    Profile photo of Tobias
    Tobias
    Participant
  • #28242
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Its a little more complicated than you stated as it works fine for me in the PowerShell console but I can reproduce the problem in ISE

You must be logged in to reply to this topic.