Ying Li at myITforum.com

PowerShell & System Center

Powershell script to get network adapter names from a list of clients

The script below is nothing special. It is usual WMI query and reporting in excel stuff. The reason I want to post this script is because this line: where {$_.name -match "[HC]* NC*"}.

This is so called PowerShell “Wildcard expressions”. It replaces the following code:

{$_.name -like "HP NC*"-or $_.name -like "COMPAQ NC*"}.

As expected, it returns all the Network Adapter from HP and COMPAQ

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "Network Adapter Name"
$c.Cells.Item(1,3) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

Foreach ($strComputer in get-content C:\PS\bkups.txt)
{
$c.Cells.Item($intRow,1)  = $strComputer
$Adapters = Get-WMIObject Win32_NetworkAdapter -computer $strcomputer |where {$_.name -match "[HC]* NC*"}
Foreach ($Nic in $Adapters)
{
$c.Cells.Item($intRow,2) = $Nic.name

$c.Cells.Item($intRow,3) = Get-Date
$intRow = $intRow + 1
}
}
$d.EntireColumn.AutoFit()
cls

 

Posted: May 17 2007, 03:36 PM by yli628 | with no comments
Filed under:

Comments

No Comments