Jump to content

Recommended Posts

Posted

Hello

 

I have a script which will read a CSV file of computer names and output the adapter name and speed '100' or '1000', however the results don't include the computer name.

 

Could anyone help me adjust the script so that it will include the PC name in the output?

 

Thanks in advance.

 

SCRIPT:

 

Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName (gc pclist.txt) | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}

 

OUTPUT:

 

Name LinkSpeed(MB)

---- -------------

Realtek PCIe GBE Family Controller 100

isatap.xxxxxx 0

Atheros L1 Gigabit Ethernet 10_100_1000Base-T Controller 100

isatap.xxxxx 0

Posted (edited)

Managed to quickly hack something together that uses a txt file rather than a CSV (can't get the CSV working quickly for some reason but I'm not that great at powershell, plus i've quickly done this on lunch), just have one computer name per line in the txt file.

 

$Computers = Get-Content -Path 
foreach ($computer in $Computers) {
Write-Host "$Computer"
Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}
}

 

EDIT: Ok managed to do it with a CSV, this script assumes the column header name for the computers names list in the CSV is 'ComputerNames'

 

$Computers = Import-CSV 
foreach ($Computer in $Computers) {
$Item = $Computer.ComputerNames
Write-Host $Item
Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $Item | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}
}

Edited by LinkZ
Posted

Receiving this error when try to run:

 

PS U:\> $Computers = Get-Content -Path C:\AA\2\pclist.txt foreach ($computer in $Computers) { Write-Host "$Computer" Get

-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSpee

d(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}} }

Unexpected token 'in' in expression or statement.

At line:1 char:72

+ $Computers = Get-Content -Path C:\AA\2\pclist.txt foreach ($computer in <<<< $Computers) { Write-Host "$Computer" Ge

t-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSp

eed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}} }

+ CategoryInfo : ParserError: (in:String) [], ParentContainsErrorRecordException

+ FullyQualifiedErrorId : UnexpectedToken

 

 

QUOTE=LinkZ;1311813]Managed to quickly hack something together that uses a txt file rather than a CSV (can't get the CSV working quickly for some reason but I'm not that great at powershell, plus i've quickly done this on lunch), just have one computer name per line in the txt file.

 

$Computers = Get-Content -Path C:\AA\2\pclist.txt
foreach ($computer in $Computers) {
Write-Host "$Computer"
Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}
}

Posted
Try the CSV version I edited in instead, also paste this into the powershell ISE rather than a console and run it from there. In your output it seems you haven't changed the location for the CSV, have you created this folder structure on your machine and pasted yours there? Otherwise edit the location in the script.
Posted

This should work, it's not pretty but it does the job in a single line (and even tests if a machine is online before trying to get the data)

 

Import-Csv -Path E:\Test\ComputerTest.csv | % { if (Test-Connection $_.ComputerName -Count 1 -quiet) { Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $_.ComputerName | Format-Table $_.ComputerName,Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1MB}}}}

 

I can probably tidy it up a bit more so it outputs some nicer data, especially if you want it out to csv or something.

Posted
This should work, it's not pretty but it does the job in a single line (and even tests if a machine is online before trying to get the data)

 

Import-Csv -Path E:\Test\ComputerTest.csv | % { if (Test-Connection $_.ComputerName -Count 1 -quiet) { Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $_.ComputerName | Format-Table $_.ComputerName,Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1MB}}}}

 

I can probably tidy it up a bit more so it outputs some nicer data, especially if you want it out to csv or something.

 

Nice, there's some motivation for me to carry on reading my powershell book!

Posted

Cheers your a Genius! - I've got it working now with the txt file from the ISE - just times out with RPC if the PC is off

couldn't get the last code to work checking if the PC was on first.

Posted

So.....I added in a list of several PC's - if one is offline it times out with RPC error carries on, then if it finds another PC which is off then it just sits there stuck!

 

- - - Updated - - -

 

Cancel that - just took a while one 1 pc..

 

So.....I added in a list of several PC's - if one is offline it times out with RPC error carries on, then if it finds another PC which is off then it just sits there stuck!
Posted
So.....I added in a list of several PC's - if one is offline it times out with RPC error carries on, then if it finds another PC which is off then it just sits there stuck!

 

- - - Updated - - -

 

Cancel that - just took a while one 1 pc..

 

To speed that up add look at my code for using Test-Connection in an IF statement and it will spend ~5s on a machine which is off and move to the next one.

Posted

With your script below which is working do you have a way to then pipe the output to a text file? Then I can search for PCs only on 100 meg.

thanks :)

 

$Computers = Get-Content -Path C:\AA\2\pclist.txt

foreach ($computer in $Computers) {

Write-Host "$Computer"

Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}

}

Posted
With your script below which is working do you have a way to then pipe the output to a text file? Then I can search for PCs only on 100 meg.

thanks :)

 

$Computers = Get-Content -Path C:\AA\2\pclist.txt

foreach ($computer in $Computers) {

Write-Host "$Computer"

Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1000000 -as [int]}}

}

 

Easier than that would be something like this:

 

$Computers = Get-Content -Path C:\AA\2\pclist.txt
foreach ($computer in $Computers) {
Write-Host "$Computer"
Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -ComputerName $computer | Where {$_.CurrentBandwidth -le 100MB} |  Format-Table Name,@{label="LinkSpeed(MB)";Expression={$_.CurrentBandwidth/1MB]}}
}

 

That will filter results as they come in and only display ones with 100MB or lower connections. To put it to a text file would just mean swapping the Format-Table section for Add-Content -Path C:\Path\to\File.txt, though you'd probably want Export-Csv -Path C:\Path\To\File.csv -Append -NoTypeInformation to make it easier to work with in excel etc.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...