Enumerate Operating Systems

Enumerate Operating Systems

# Get a list of computers in the domain:
Get-NetComputer

# Get the operating system and DNS hostname for each computer:
# Using this way we can select any value which is required.
# Example:Get
Get-NetComputer | select operatingsystem,dnshostname
# List of Computer present in the domain with cn
Get-NetComputer | select operatingsystem,dnshostname, cn | Format-Table -Wrap -AutoSize

# To get ip address also
# Takes time to run !!!
Get-NetComputer | Select operatingsystem, dnshostname, cn | ForEach-Object { $_ | Add-Member -NotePropertyName IPAddress -NotePropertyValue ($(if ($_.dnshostname) { $ipAddresses = (nslookup $_.dnshostname 2>&1 | Select-String 'Address:\s*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }); if ($ipAddresses.Count -gt 1) { $ipAddresses[1] } else { "N/A" } } else { "N/A" })); $_ } | Format-Table operatingsystem, dnshostname, cn, IPAddress -Wrap -AutoSize


Last updated