Solved

Outputting speed results to a csv file

Posted on 2014-09-26
2
172 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
[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: 40346362
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
ID: 40346567
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

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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