PowerShell script to search for computers in the domain control

1 minute reading time (279 words)
monitor_showing_a_program_scanning_computers_throu_6e5d3c88-2d3e-493d-bfcf-4e89e0a32e1b

 Here's the PowerShell script to search for computers in the domain control and report the details you've requested:

# Define the domain name
$domain = "yourdomain.com"

# Get all computers in the domain
$computers = Get-ADComputer -Filter * -Properties IPv4Address, Description | Select-Object Name, IPv4Address, Description

# Loop through each computer and gather the details
foreach ($computer in $computers) {
    # Get the MAC address
    $macAddress = (Get-WmiObject win32_networkadapterconfiguration -ComputerName $computer.Name | Where-Object {$_.IPEnabled -eq $true}).MACAddress

    # Get the SID
    $sid = (Get-WmiObject win32_useraccount -ComputerName $computer.Name | Where-Object {$_.SID -match "S-1-5-21"}).SID

    # Get the computer type based on the description field
    if ($computer.Description -match "laptop") {
        $computerType = "Laptop"
    }
    elseif ($computer.Description -match "desktop") {
        $computerType = "Desktop"
    }
    elseif ($computer.Description -match "virtual machine") {
        $computerType = "Virtual Machine"
    }
    elseif ($computer.Description -match "docker unit") {
        $computerType = "Docker Unit"
    }
    elseif ($computer.Description -match "mac") {
        $computerType = "Mac"
    }
    elseif ($computer.Description -match "iphone") {
        $computerType = "iPhone"
    }
    elseif ($computer.Description -match "linux") {
        $computerType = "Linux"
    }
    elseif ($computer.Description -match "unix") {
        $computerType = "Unix"
    }
    else {
        $computerType = "Other"
    }

    # Output the details to the console
    Write-Host "Computer Name:" $computer.Name
    Write-Host "IP Address:" $computer.IPv4Address
    Write-Host "MAC Address:" $macAddress
    Write-Host "SID:" $sid
    Write-Host "Type:" $computerType
    Write-Host ""
} 

 This script defines the domain name and gets all computers in the domain. It then loops through each computer and gathers the details you requested. The script determines the computer type based on the description field of the computer object. Finally, the script outputs the details to the console. You can modify the script to output the details to a file or another destination if desired.


Font size: +
Report Print
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

By accepting you will be accessing a service provided by a third-party external to https://www.klokur.com/