Solved

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

Posted on 2014-01-07
2
459 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Set OWA language and time zone in Exchange for individuals, all users or per database.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

18 Experts available now in Live!

Get 1:1 Help Now