Hi,
I'm New to powershell, trying to create a small script to get macaddress from IP address.
$ipsheet = get-content c:\work\ipsheet.txt
$ipvalue=""
$macvalue=""
foreach ($ip in $ipsheet)
{if (test-Connection $ip -Count 2 -Quiet )
{ $macvalue+=(gwmi -Class Win32_NetworkAdapterConfiguration -computer $ip -filter "IpEnabled = TRUE" | where { $_.IpAddress -eq $ip }).MACAddress
} else
{
$ipvalue+=$ip
$macvalue+="not pinging"}}
I have two issues here, First the ipaddress or macaddress details collected in $ipvalue/$macvalue is continuous, i mean its not as array. I want it as array line by line. I have also tried to use `n to append data to next line but dint get it properly.
Second, i want to export this csv file in below format
Ipaddress,macaddress,
10.1.1.1,00:aa:bb:cc:dd:ee
I have checked so many forum but none of it helped much. please help.. thank you in advance.