TechShizz | List a Client Machine informations with PowerShell

List a Client Machine informations with PowerShell

Here are two scripts, which can assist in getting hardware information about the computers on an active directory network. It'll get you the following information in a CSV file:

  1. Hostname
  2. Model
  3. RAM
  4. CPU
  5. Serial Number
  6. Manufacturer
  7. Operating System
  8. HDD Capacity
  9. HDD Space
  10. IP Address

If your DC has PowerShell V2 use this:

## FOR MACINES WITH POWERSHELL V2
Import-Module ActiveDirectory
$ComputerList = Get-ADComputer -filter * -Properties *
$csvpath = "C:\users\icuadminaccount\Desktop\Computers.csv"
foreach ($Computer in $ComputerList) {
##Title
$computerSystem = Get-WmiObject -ComputerName $Computer.Name -Class CIM_ComputerSystem
$output = "System Information for: " + $computerSystem.Name +"`n"
$output = $output + "Model: " + $computerSystem.Model +"`n"
$output = $output + "RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"+"`n"
##CPU
$computerCPU = Get-WmiObject -ComputerName $Computer.Name -Class CIM_Processor
$output = $output + "CPU: " + $computerCPU.Name +"`n"
Out-file -FilePath $csvpath -append
##BIOS
$computerBIOS = Get-WmiObject -ComputerName $Computer.Name -Class CIM_BIOSElement
$output = $output + "Serial Number: " + $computerBIOS.SerialNumber +"`n"
$output = $output + "Manufacturer: " + $computerBIOS.Manufacturer +"`n"
Out-file -FilePath $csvpath -append
##OS
$computerOS = Get-WmiObject -ComputerName $Computer.Name -Class CIM_OperatingSystem
$output = $output + "Last Reboot: " + $computerOS.LastBootUpTime +"`n"
$output = $output + "Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion +"`n"
Out-file -FilePath $csvpath -append
##Disks
$computerHDD = Get-WmiObject -ComputerName $Computer.Name -Class Win32_LogicalDisk -filter "DeviceID = 'C:'"
$output = $output + "HDD Capacity: " + "{0:N2}" -f ($computerHDD.Size/1024) + "GB" +"`n"
$output = $output + "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/1024) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace) + "KB)" +"`n"
$output | Out-file -FilePath $csvpath -append
}

If your DC has PowerShell V3+ use this:

## FOR MACINES WITH POWERSHELL V3+
Import-Module ActiveDirectory
$ComputerList = Get-ADComputer -filter * -Properties *
$csvpath = "C:\users\icuadminaccount\Desktop\Computers.csv"
foreach ($Computer in $ComputerList) {

$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:'"


$output = "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
$output = $output + "Manufacturer: " + $computerSystem.Manufacturer
$output = $output + "Model: " + $computerSystem.Model
$output = $output + "Serial Number: " + $computerBIOS.SerialNumber
$output = $output + "CPU: " + $computerCPU.Name
$output = $output + "HDD Capacity: " + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
$output = $output + "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
$output = $output + "RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
$output = $output + "Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
$output = $output + "User logged In: " + $computerSystem.UserName
$output = $output + "Last Reboot: " + $computerOS.LastBootUpTime
$output | Out-file -FilePath $csvpath -append
}

Add comment