Get-NetAdapterPowerManagement

Lanky Doodle 241 Reputation points
2023-09-22T18:26:58.7766667+00:00

Hi,

I need to return a list of only supported properties for each nic from a predefined list of properties. That is, any property from the predefined list that does not have a value of 'Unsupported'. I haven't yet found a way to filter on the Disabled|Enabled|Unsupported valueUser's image

The 2nd command shows the output I want to achieve, without only selecting that property.

Adding ? { $_ -ne "Unsupported" } does not work. What is the 'column' name of the actual values Disabled|Enabled|Unsupported?

Thanks

PS: This cmdlet is possibly the most frustrating one I've ever used.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,026 Reputation points
    2023-09-23T03:14:34.1166667+00:00

    You can try something like this:

    $props = 
    "AllowComputerToTurnOffDevice",
    "D0PacketCoalescing",
    "DeviceSleepOnDisconnect",
    "ArpOffload",
    "NSOffload",
    "RsnRekeyOffload",
    "SelectiveSuspend",
    "WakeOnMagicPacket",
    "WakeOnPattern"
    
    Get-NetAdapter | 
        ForEach-Object {
            $desc = $_.InterfaceDescription
            $name = $_.Name
            Get-NetAdapterPowerManagement -Name $name |
                ForEach-Object{
                    $h =    [ordered]@{ InterfaceDescription = $desc
                                        Name = $name
                                      }
                    ForEach ($prop in $props){
                        $h[$prop] = ""                      # you need ALL properties in order to produce output that makes sense
                                                            # This has to do with the way objects are displayed (or exported)
                                                            # => the first objects properties will determine the properties
                                                            #    displayed for all subsequent objects!
                        if ($_.$prop -ne "Unsupported"){
                            $h.$prop = $_.$prop
                        }
                    }
                    [PSCustomObject]$h
                }
            }
    

    OR, if you want only a simple tabulation:

    $props = 
    "AllowComputerToTurnOffDevice",
    "D0PacketCoalescing",
    "DeviceSleepOnDisconnect",
    "ArpOffload",
    "NSOffload",
    "RsnRekeyOffload",
    "SelectiveSuspend",
    "WakeOnMagicPacket",
    "WakeOnPattern"
    
    Get-NetAdapter | 
        ForEach-Object {
            $desc = $_.InterfaceDescription
            $name = $_.Name
            Get-NetAdapterPowerManagement -Name $name | #-InterfaceDescription $_.InterfaceDescription |
                ForEach-Object{
                    $name
                    $desc
                    ForEach ($prop in $props){
                        if ($_.$prop -ne "Unsupported"){
                            "`t$prop"
                        }
                    }
                    "==============================================="
                }
            }
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.