Link to home
Start Free TrialLog in
Avatar of sherlock1
sherlock1

asked on

Powershell script to get computer information from all servers in an AD domain

Hi Experts,

I am using the below powershell script to get various server information from the local server and output to a CSV file but was wondering if it was possible to adapt to get the computer information for all servers (servers mostly running Windows server 2016) on an AD domain. Is this possible?

$computerSystem = Get-CimInstance CIM_ComputerSystem
$computerBIOS = Get-CimInstance CIM_BIOSElement
$computerOS = Get-CimInstance CIM_OperatingSystem
$computerCPU = Get-CimInstance CIM_Processor
$computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$netadapter = Get-WmiObject win32_networkadapterconfiguration -Filter IPEnabled=TRUE -ComputerName $Computer

$Object = New-Object PSObject -Property @{
    "Computer Name" = $computerSystem.Name
    "Operating System" = $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
    "Manufacturer" = $computerSystem.Manufacturer
    "Model" = $computerSystem.Model
    "Serial Number" = $computerBIOS.SerialNumber
    "CPU" = $computerCPU.Name
    "HDD Capacity" = "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
    "HDD Space" = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
    "RAM" = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
    "MAC Address" = $netadapter.MACAddress
    "DHCP Enabled" = $netadapter.DHCPEnabled
    "IP Address" = $netadapter.IPAddress
    "Subnet Mask" = $netadapter.IPSubnet
    "Defaul Gateway" = $netadapter.DefaultIPGateway
    "Domain/Workgroup Name" = $netadapter.DNSDomain
    "User logged In" = $computerSystem.UserName
    "Last Reboot" = $computerOS.LastBootUpTime
}

$Object | Export-Csv c:\Temp\systeminfo.csv -NoTypeInformation


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Robert
Robert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sherlock1
sherlock1

ASKER

Thanks a lot Robert and Jose for your suggestions