Inventory your Network and Clients

Many organizations have a wide range of computers and users, for us system administrators it is difficult to get an overview. Yes, SCCM provides a list of all users who logged on previously, but can we rely on these log files? My manager asked me to retrieve a complete list of all computers and users and SCCM was the first option. The list SCCM provided was incomplete and 60% of all entries didnít have a NetworkLoginProfile or outdated user profile. 60% of 1000+ computers is muchÖ

Well how to tackle this issue:

The PowerShell command below retrieves every ip-address per user, mac-address, the user account and there computer and creates a .csv file of the result.

  1. Open PowerShell on the DC.

  2. Paste the following code in the command prompt:

PowerShell

import-module activedirectory
Get-ADComputer -Filter ëName -like ì*îë | Select-Object Name | epcsv Allcomputers.txt
gc Allcomputers.txt | % {$_ -replace ëîë , ìî} | Set-Content computers.txt
gc computers.txt | ? {test-connection $_ -quiet -Count 1 -ea 0} | % {
$Networks = gwmi Win32_NetworkAdapterConfiguration -ComputerName $_ | ? {$_.IPEnabled}
gwmi Win32_NetworkLoginProfile -ComputerName $_ | Sort -Descending LastLogon |
Select | ? {$_.LastLogon -like ì20120317*î} | % {
Foreach ($Network in $Networks) {
$IPAddress = $Network.IpAddress[0]
$MACAddress = $Network.MACAddress
}
New-Object PSObject -Property @{
ComputerName = $_.__Server
UserName = $_.Name
LastLogon = $LastLogon
IpAddress = $IPAddress
MACAddress = $MACAddress
}
} | Select IpAddress,MACAddress,UserName,ComputerName | ConvertTo-Csv | Select -Last 1 | ac CompleteList.csv
}

Filter

* Donít retrieve every pc: Domain Controllers and other servers are included as well if you filter with * only. Use the computer naming convention of your company for example: -like ìNLABC-*î to retrieve the client computers only.

Conclusion

This PowerShell command gives you approximately 90% results, run the script a couple of times and compare the list with each other. Of course there is 10% that will never be retrieved, (hardware damage and network related issues etc.).