Assistance with script to find IP and Mac Address from a list of computer.txt
hello,
i have working script gives me need...but it's writing out in triplicate of computers , can't see why? can see i've done wrong in code cause this:
[cmdletbinding()] param ( [parameter(valuefrompipeline=$true,valuefrompipelinebypropertyname=$true)] [string[]]$computername = $env:computername ) begin {} process { foreach ($computer in (gc .\computers.txt)) { if(test-connection -computername $computer -count 1 -ea 0) { $networks = get-wmiobject win32_networkadapterconfiguration -computername $computer | ? {$_.ipenabled} foreach ($network in $networks) { $ipaddress = $network.ipaddress $macaddress = $network.macaddress $outputobj = new-object -type psobject $outputobj | add-member -membertype noteproperty -name details -value $computer.toupper(), $ipaddress, $macaddress $outputobj } } } } end {}
the results show follows:
details ------- {pcnum1, 10.100.11.100, 00:17:5e:70:10:06} {pcnum2, 10.100.11.101, 00:17:5e:70:15:65} {pcnum2, 10.100.11.101, 00:17:5e:70:15:65} {pcnum2, 10.100.11.101, 00:17:5e:70:15:65} {pcnum3, 10.100.11.99, 00:17:5e:70:15:52}
as can see, pc name pcnum2 shows 3 times.
any appreciated.
if run
get-wmiobject win32_networkadapterconfiguration -computername pcnum2 | ? {$_.ipenabled}
...do 3 adapters?
is pcnum2 included more once in .\computers.txt?
i rid of pipeline stuff well: begin, process , end blocks... looks it's not being used.
prove can results want before getting clever it.
i create object , use method... (just example... )
$existingdata contains collected data#this array definition goes @ beginning... outside loop
$existingdata=@()
#within loop, add new object existing array
$existingdata+=new-object psobject -property @{'computer'=$computer;'ip'=$network.ipaddress;'mac'=$network.macaddress}
inspired heineken.
Windows Server > Windows PowerShell
Comments
Post a Comment