Hello there, Next question.
I have 2 scripts, 1 is working, one is not. But I don’t know why one is not working. It looks ok for me.
first i will use the working one:
I have a CSV file on my computer. The first few lines are these:
A;B
00-00-0C;Cisco Systems, Inc
00-00-0D;FIBRONICS LTD.
00-00-0E;FUJITSU LIMITED
00-00-1B;Novell, Inc.
I import this file like this:
$map = @{}
Import-Csv C:\tmp\mac-vendors-export.csv -Delimiter ';' | ForEach-Object {
$map[$_.A] = $_.B
}
What i want allready have achieved is to scan my network. retrieve mac addresses, and then compare it with this CSV, and show the corresponding column B result.
VendorList = $vendorMac | ForEach-Object {
[pscustomobject]@{
MAC = $_
Vendor = $map[$_]
}
BUT, i have to go a step further. because in real live i don’t have this file on my computer. So i have to download it, and compare it after this. But the downloaded file is a litte different formatted.
so my code look like this:
invoke-webrequest -uri "https://maclookup.app/downloads/csv-database/get-db?t=22-12-28&h=a6f90f116bc4364ad17817cff62fd160fbff73c0" -outfile $Env:temp\mac-vendor.csv
the file look like this:
Mac Prefix,Vendor Name,Private,Block Type,Last Update
00:00:0C,“Cisco Systems, Inc”,false,MA-L,2015/11/17
00:00:0D,FIBRONICS LTD.,false,MA-L,2015/11/17
00:00:0E,FUJITSU LIMITED,false,MA-L,2018/10/13
00:00:1B,“Novell, Inc.”,false,MA-L,2016/04/27
00:00:23,ABB INDUSTRIAL SYSTEMS AB,false,MA-L,2015/11/17
Import-CSV $ENV:Temp\mac-vendor.csv -Delimiter ',' -Header 'MAC','Vendor' | Select-object 'MAC','Vendor' -Skip 1 | ForEach-Object {
$map[$_.MAC] = $_.Vendor
}
$VendorList = $vendormac | ForEach-Object {
[pscustomobject]@{
MAC = $_
Vendor = $map[$_]
}
}
I see when i show the $vendorlist variable i receive no vendors
PS C:\WINDOWS\system32> $VendorList
MAC Vendor
74-83-c2
d2-51-e5
60-ab-14
18-e8-29
bc-cf-4f
2e-d9-2c
00-11-32
c0-3f-d5
18-e8-29
And in the working script it’s filled with information
so it must be somewhere in this part i think
$vendormac | ForEach-Object {
[pscustomobject]@{
MAC = $_
Vendor = $map[$_]
}
}
I hope my question is clear enough