Solved

Outputting speed results to a csv file

Posted on 2014-09-26
2
164 Views
Last Modified: 2014-09-26
I am attempting to import a csv file that i made from exporting a list of computers from Active Directory.  The file is blank when it exports. Any assistance would help. Here is the code  
$Computers = Import-csv -path c:\NicSpeeds\jhcomputer.csv
$speed = "C:\NicSpeeds\speed.csv"
Foreach ($Computer in $Computers) {
    Get-WmiObject -Computer $Computer -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Select-object SystemName,Name,NetConnectionID,@{label='Speed(MB)';Expression = {$_.Speed/1MB}} | export-csv -path $speed -append -notypeinformation
}

Open in new window

0
Comment
Question by:falconcurt
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
When you use Import-CSV, it creates custom objects with properties determined by the headers in the file.  So you need to reference the particular property of that object that you want to use.  So you probably want to modify line 4.
Get-WmiObject -Computer $Computer.name -Class Win32_NetworkAdapter | `

Open in new window


Secondary issue - it's typically better for performance reasons not to append to a file within a foreach loop to avoid repeatedly opening and closing the file.  Something like the below is better.
$speed = "C:\NicSpeeds\speed.csv"
Import-csv -path c:\NicSpeeds\jhcomputer.csv | Foreach {
    Get-WmiObject -Computer $_.Name -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Select-object SystemName,Name,NetConnectionID,@{label='Speed(MB)';Expression = {$_.Speed/1MB}}
} | export-csv -path $speed -append -notypeinformation

Open in new window

0
 

Author Comment

by:falconcurt
Comment Utility
I actually just found out before you posted what my problem was regarding line 4. I did however use your recommendation on having the export statement after my foreach loop. Thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

14 Experts available now in Live!

Get 1:1 Help Now