In addition to other answers, here are some useful information that can be retrieved using PowerShell:
Querying OS & Hardware Info via PowerShell:
Querying General OS (Operating System) Information:
Quickest way to view the OS name:
cmd ?
#Using Get-ComputerInfo:
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
#Using Get-WmiObject:
$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Write-Host " OS-Name: `t $name `n Architct: `t $bit `n Release: `t $ver"
To list Major Minor Version info:
[System.Environment]::OSVersion.Version
Querying HostName:
$Env:ComputerName
OR
hostname #cmd command
Also, if you know the IP address, use the "ping" command (e.g.: ping /a <your_ip_address>
) you will see your "hostname" in first line.
Querying Current (Logged-in) User:
whoami #cmd command
OR
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
Querying Mapped Drives:
List Mapped Drives - using WMI:
Get-WmiObject -Class Win32_LogicalDisk | Format-Table
OR
wmic logicaldisk get name #list just logical-drive letters
OR, to list logical-drive info: FreeSpace, Provider (Real Network Location), Size, and VolumeName:
wmic logicaldisk list brief
List Mapped Drives - using [DriveInfo] class:
[System.IO.DriveInfo]::GetDrives()
List Removable Drives:
$drives = [System.IO.DriveInfo]::GetDrives()
$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }
if ($r) {
return @($r)[-1]
}
Querying disk capacity, space & Volume-Type
Invoke-Command -ComputerName S1 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free
Free Space:
(Get-PSDrive C).Free
OR (in GB)
[Math]::Floor(((Get-PSDrive C).Free /[Math]::Pow(2, 30)*10)) /10
Used Space:
(Get-PSDrive C).Used
OR (Used space in GB's)
[Math]::Floor(((Get-PSDrive C).Used /[Math]::Pow(2, 30)*10)) /10
Additionally to view total Space: (in GB)
$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/(1024*1024*1024)
OR
$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/[Math]::Pow(2, 30)
Rounded off values:
[Math]::Floor($totalSpace*10) / 10
OR
[Math]::Round($totalSpace,1)
Querying Motherboard info:
wmic baseboard get product,Manufacturer,version,serialnumber
Querying Disk Volume (Of Disk Partitions) Info:
Get-Volume returns information about storage drive's partitions, e.g.:
Get-Volume # All partitions
Get-Volume -DriveLetter C # Specific partition
#file system type:
Get-Volume -DriveLetter C | select FileSystem
(Get-Volume -DriveLetter C).FileSystem
#partition size:
Get-Volume -DriveLetter C | select Size
OR (in GB)
[Math]::Floor(((Get-Volume -DriveLetter C).Size/[Math]::Pow(2, 30)*10)) /10
Querying Memory / Query RAM
Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
OR (in GB)
$memory = (Get-WmiObject Win32_PhysicalMemory | Measure -Property Capacity -Sum).Sum
$memory = [Math]::Floor(($memory/[Math]::Pow(2, 30)*10)) /10
$memory.ToString() + " gb"
#Query RAM including Frequency / Speed:
Get-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber –autosize
As mentioned, this answer goes bit beyond the question asked, but could be useful for those who'd like additional OS or Hardware information using PowerShell.