Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Outputting speed results to a csv file

Posted on 2014-09-26
2
Medium Priority
?
176 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 41

Accepted Solution

by:
footech earned 2000 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

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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