I'm trying to find out who is in the office and who's not by checking the IPv4 Address range. Anyone with an IP address starting with 10.57.xx.xx Is in the office and anyone with IP 10.53.xx.xx is working on a VPN. I would like to export their domain usernames from the list of people in the office.
How can I do this using PowerShell?
This is what I have (unfinished)
$Machines = (Get-ADComputer -Filter * -SearchBase 'OU=Laptops,OU=Win10Modern,OU=LN,OU=Workstations,DC=cooley,DC=com').Name
$result = foreach ($Machine in $Machines)
{
if (Test-Connection -ComputerName $Machine -Count 1 -Quiet) {
if($machine.ipaddress -like "10.57*")
{
Get-WmiObject –ComputerName $Machine –Class Win32_ComputerSystem | Select-Object Username
}
}
}