I need to get a list of properties for multiple server, but I'm stuck with the output of second command in my loop:
$(foreach ( $Net in $Nets ) {
Get-NetAdapterBinding -ComponentID ms_msclient,ms_server,ms_tcpip6 -ErrorAction SilentlyContinue | select Name,DisplayName,Enabled
Get-NetAdapterAdvancedProperty $Net -DisplayName "Speed & Duplex" | select DisplayValue
}) | Format-List
The output of first cmd is correct:
Name : LAN_Clients
DisplayName : Internet Protocol Version 6 (TCP/IPV6)
Enabled : False
Name : LAN_Clients
DisplayName : File and Print Sharing
Enabled : False
Name : LAN_Clients
DisplayName : Client for Microsoft Networks
Enabled : False
The second cmd seems ignored... If I run cmd manually the output is correct:
Get-NetAdapterAdvancedProperty "LAN_Clients" -DisplayName "Speed & Duplex" | select DisplayValue
DisplayValue
------------
Auto Negotiation
What am I doing wrong?
$Net, and ensure a name is actually being passed to it?foreach.$Nets = get-NetAdapterFormat-List, all output should show. With default output (impliedFormat-Table), the first output object locks in all output columns based on its properties, so theDisplayValueproperty from the 2nd command never shows - see this answer.foreachblock, and whatever these constructs output becomes theforeachstatement's overall output. The problem is merely a display problem, due to how (implicitly applied)Format-Tableformatting works; again, see the previously linked answer.