Solved

Outputting speed results to a csv file

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

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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