Solved

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

Posted on 2014-01-07
2
460 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
2 Comments
 
LVL 39

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now