PowerShell script to get computer information
Scenario:
PowerShell script to get computer information.
When there is a support case, the first thing that you need to do it to gather as much information as possible related to the issue, so you will start troubleshooting. The information that you can receive from a computer using PowerShell is a lot. In cases that some software may run slow and in general the PC of a user is slow, the first thing that you need to know is what PC is using and some basic specifications. I came up with this simple script to receive the basic information and present it to you so you will be able to see those specifications. In general the script will gather information about Manufacturer and Model, CPU, RAM, Disks and Operating System.
Let see in more detail
The first part of the script in only the help information that is provided through Get-Help for the script. To run the script you need to provide always the computer name of the PC. The script first will receive the value that you have provided and will test if the PC is reachable. If the value that you have provided is wrong or the PC is not reachable then it will inform you and will exit. If the value is correct and the computer is reachable, then it will start the process of gathering the information from the computer.
Hardware Information
The first information that the script will gather is the Manufacturer and Model of the PC. After that the script will collect the information for the CPU/s. It will get the id of the CPU if there are multiple CPUs and the model of the CPU. The next two commands are related to the information of RAM. The first command check the number of RAM DIMMs that the PC has and also the total RAM of the PC. Please note that the value provided for the Total RAM Capacity is in KBytes. The second command will gather the information for each DIMM. It will provide us with the location on the Motherboard, the manufacturer of the RAM and the part number, the capacity of each DIMM and the speed that is configured.
The script will continue on the information from the disks and will receive the information from the disk such as Drive Letter, the name of the drive if it exists, total size of the disk and the free space. Please note that the Disk sizes are provided in Bytes.
Operating System Version
The script as a final information will gather the version of Windows. The version is provided in released version number based on NT System. As this was not clear which was the version, I had to relate the edition number with a common name with is more readable. The script has been tested only on Windows 8.1 and Windows 10, but in the list I have included also Windows 7. Any other Windows version it will give you Unknown Operating System. It is unknown, not because you cannot retrieve the information but because I have not correlate it with any Windows version. Another important thing that it has to be mentioned is the Windows Servers, have the same NT release version. In this script I have not considered any Windows Server modes, so the Operating System information will be wrong.
This is only a simple script that retrieves basic information. In related links you can find another script which has includes more functionality and you are able to retrieve more information from the remote computers or servers. Check it out you might find it interesting too.
You can download the script here or copy it from below.
Hope you like it. If you have any questions or anything else please let me know in the comments below.
Related Links:
- Test-Connection – Microsoft Docs
- Get-WmiObject – Microsoft Docs
- Write-Host – Microsoft Docs
- Write-Output – Microsoft Docs
- How to get remote system information – Part 1
- How to get remote system information – Part 2
- How to get remote system information – Part 3
Solution / Script:
<#
.SYNOPSIS
Name: Get-PCInfo.ps1
The purpose of this script is to retrieve basic information of a PC.
.DESCRIPTION
This is a simple script to retrieve basic information of domain joined computers.
It will gather hardware specifications and Operating System and present them on the screen.
.RELATED LINKS
Home
.PARAMETER Computer
This is the only parameter that is needed to provide the name of the computer either
in as computer name or DNS name.
.NOTES
Updated: 08-02-2018 Testing the connection before the information gathering.
Release Date: 05-02-2018
Author: Stephanos Constantinou
.EXAMPLE
Run the Get-PCInfo script to retrieve the information.
Get-PCInfo.ps1 -Computer test-pc
#>
Param( [string]$Computer )
$Connection = Test-Connection $Computer -Count 1 -Quiet
if ($Connection -eq "True") {
$ComputerHW = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer |
select Manufacturer,Model | FT -AutoSize
$ComputerCPU = Get-WmiObject win32_processor -ComputerName $Computer |
select DeviceID,Name | FT -AutoSize
$ComputerRam_Total = Get-WmiObject Win32_PhysicalMemoryArray -ComputerName $Computer |
select MemoryDevices,MaxCapacity | FT -AutoSize
$ComputerRAM = Get-WmiObject Win32_PhysicalMemory -ComputerName $Computer |
select DeviceLocator,Manufacturer,PartNumber,Capacity,Speed | FT -AutoSize
$ComputerDisks = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName $Computer |
select DeviceID,VolumeName,Size,FreeSpace | FT -AutoSize
$ComputerOS = (Get-WmiObject Win32_OperatingSystem -ComputerName $Computer).Version
switch -Wildcard ($ComputerOS) {
"6.1.7600" {$OS = "Windows 7"; break}
"6.1.7601" {$OS = "Windows 7 SP1"; break}
"6.2.9200" {$OS = "Windows 8"; break}
"6.3.9600" {$OS = "Windows 8.1"; break}
"10.0.*" {$OS = "Windows 10"; break}
default {$OS = "Unknown Operating System"; break}
}
Write-Host "Computer Name: $Computer"
Write-Host "Operating System: $OS"
Write-Output $ComputerHW
Write-Output $ComputerCPU
Write-Output $ComputerRam_Total
Write-Output $ComputerRAM
Write-Output $ComputerDisks
}
else {
Write-Host -ForegroundColor Red @"
Computer is not reachable or does not exists.
"@
}
[…] on February 7, 2018 submitted by /u/SConstantinou [link] [comments] Leave a […]