Solved

Outputting speed results to a csv file

Posted on 2014-09-26
2
174 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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