Avatar of defecta
defecta
Flag for Australia

asked on 

PowerShell noob: script optimisation. Is there a better way to do this?

Hey guys,

I am trying to hack my way through teaching myself PowerShell by looking at code examples online and doing a lot of testing and reading. I am also working my way through some books that I bought but I haven't yet learned what a better way to do what I am doing here in this code example.

Basically i want to see ALL the methods and properties and their values listed for the WMI object "Win32_NetworkAdapterConfiguration" in the code example shown below, not just the rather brief version that it returns if no other format parameters are specified.

$member = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computerName | Where { $_.IPEnabled -eq $enabledAdapters} | get-member

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computerName | Where { $_.IPEnabled -eq $enabledAdapters} | Format-list $member.name

Open in new window


This code example does what I want but it seems awfully verbose to me. Is there a more clever and concise to acheive the same output?

Cheers,
AC
PowershellScripting LanguagesShell Scripting

Avatar of undefined
Last Comment
defecta

8/22/2022 - Mon