除了其他回答之外,以下是一些可以使用PowerShell检索的有用信息:
通过PowerShell查询操作系统和硬件信息:
查询通用操作系统信息:
查看操作系统名称最快的方法:
cmd ?
#使用 Get-ComputerInfo:
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
#使用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"
列出主要和次要版本信息:
[System.Environment]::OSVersion.Version
查询主机名:
$Env:ComputerName
或
hostname #cmd command
另外,如果您已知IP地址,请使用“ping”命令(例如:ping /a <your_ip_address>
),您将在第一行看到您的“主机名”。
查询当前(登录)用户:
whoami #cmd command
或者
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
查询映射驱动器:
使用WMI列出映射的驱动器:
Get-WmiObject -Class Win32_LogicalDisk | Format-Table
或者
wmic logicaldisk get name #list just logical-drive letters
或者,列出逻辑驱动器信息:FreeSpace、Provider(真实网络位置)、Size 和 VolumeName:
wmic logicaldisk list brief
列出已映射的驱动器 - 通过 [DriveInfo] 类:
[System.IO.DriveInfo]::GetDrives()
列出可移动驱动器:
$drives = [System.IO.DriveInfo]::GetDrives()
$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }
if ($r) {
return @($r)[-1]
}
查询磁盘容量、空间和卷类型
Invoke-Command -ComputerName S1 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free
可用空间:
(Get-PSDrive C).Free
或者(在GB中)
[Math]::Floor(((Get-PSDrive C).Free /[Math]::Pow(2, 30)*10)) /10
已用空间:
(Get-PSDrive C).Used
OR(已使用的空间,以GB为单位)
[Math]::Floor(((Get-PSDrive C).Used /[Math]::Pow(2, 30)*10)) /10
此外,查看总空间:(以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)
舍入后的值:
[Math]::Floor($totalSpace*10) / 10
OR
[Math]::Round($totalSpace,1)
查询主板信息:
wmic baseboard get product,Manufacturer,version,serialnumber
查询磁盘分区信息:
Get-Volume 返回存储驱动器分区的信息,例如:
Get-Volume # All partitions
Get-Volume -DriveLetter C # Specific partition
#文件系统类型:
Get-Volume -DriveLetter C | select FileSystem
(Get-Volume -DriveLetter C).FileSystem
#分区大小:
Get-Volume -DriveLetter C | select Size
OR (in GB)
[Math]::Floor(((Get-Volume -DriveLetter C).Size/[Math]::Pow(2, 30)*10)) /10
查询内存 / 查询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"
#查询内存包括频率 / 速度:
Get-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber –autosize
正如提到的那样,这个答案超出了问题的范围,但对于希望使用 PowerShell 获得更多操作系统或硬件信息的人可能会有用。