Solved

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

Posted on 2014-01-07
2
464 Views
Last Modified: 2014-01-07
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
0
Comment
Question by:defecta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39763720
Methods are another story, but with this you can view all the properties and their values.
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computerName | Where { $_.IPEnabled -eq $enabledAdapters} | Select *

Open in new window

You really can't do all methods, because the info you have to submit to them can vary wildly.
0
 

Author Closing Comment

by:defecta
ID: 39763870
Perfect, i knew it was something simple.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question