$d = "null"
$i = 0
$svrs = gc server.txt
$total = $svrs.Count
$d = foreach ($Inputmachine in $svrs )
{
$i++
try{
Write-Progress -Activity "Scanning Server .... " -Status ("Server : {0}" -f $Inputmachine ) -PercentComplete ($i/$total*100) -Id 0
}
catch{}
if (!(test-Connection -Cn $Inputmachine -quiet))
{
Write-Host "$Inputmachine : Is offline`n" -BackgroundColor Red
}
else
{
$MACAddress = "N/A"
$IPAddress = "N/A"
$IPAddress = ([System.Net.Dns]::GetHostByName($Inputmachine).AddressList[0]).IpAddressToString
#$IPMAC | select MACAddress
$IPMAC = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Inputmachine
$MACAddress = ($IPMAC | where { $_.IpAddress -eq $IPAddress}).MACAddress
Write-Host "Machine Name : $Inputmachine`nIP Address : $IPAddress`nMAC Address: $MACAddress`n"
New-Object PSObject -Property @{
ServerName = $Inputmachine
MACAddress = $MACAddress
IPAddress = $IPAddress
} | Select ServerName,IPAddress,MACAddress
}
}
$d | export-csv -notypeinformation ip&mac.csv
No comments:
Post a Comment