Afternoon all!
Long time reader, first time poster!
Self taught powersheller here so apologies if I’ve missed something super fundamental (had a search around but to no avail, again though, may not be phrasing my searches quite right due to levels of noob)
High level overview: Importing a basic 2 column csv into powershell and then querying it with a $variable to return a value
Sample CSV:
Gateway | Site |
192.168.0.1 | AA |
192.168.0.2 | BB |
192.168.0.3 | CC |
If I manually set $Gateway = 192.168.0.1 the query returns AA as expected?
Code:
$GlobalSites = Import-Csv -Path C:\SITES.csv
$Gateway = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {($.IPEnabled -eq $True) -and ($.IPAddress -ne $null)}).DefaultIPGateway | Out-String
$LocCode = $GlobalSites.where({$_.Gateway -eq "$Gateway"}).site
$LocCode
I’m almost certain its a gap/misunderstanding in my knowledge or I’m overcomplicating things.
Any help\guidance is much appreciated.
Thanks