PowerShellでPCの基本スペックを表示する

PCの基本的なスペックを表示するサンプル。ネットワークアダプタは現在接続中のアダプタのみ表示しているけど、-Filerオプション付けないと全ネットワークアダプタが表示される。
# マザーボード
$BaseBoard = Get-WmiObject Win32_BaseBoard
Write-Host "マザーボード:" $BaseBoard.Manufacturer $BaseBoard.Product

# CPU
$Processor = Get-WmiObject Win32_Processor
Write-Host "CPU:" $Processor.Name

# メインメモリ
$ComputerSystem = Get-WmiObject Win32_ComputerSystem
$MainMemory = [System.Convert]::ToInt32($ComputerSystem.TotalPhysicalMemory / (1024 * 1024 * 1024))
Write-Host "メインメモリ:" $MainMemory "GB"

$PhysicalMemories = Get-WmiObject Win32_PhysicalMemory
ForEach ($PhysicalMemory In $PhysicalMemories) {
  $MemoryCapacity = [System.Convert]::ToInt32($PhysicalMemory.Capacity / (1024 * 1024 * 1024))
  Write-Host " " $PhysicalMemory.DeviceLocator":" $PhysicalMemory.PartNumber"("$MemoryCapacity "GB)"
}

# ビデオカード
$VideoController = Get-WmiObject Win32_VideoController
$VideoMemory = [System.Convert]::ToInt32($VideoController.AdapterRAM / (1024 * 1024 * 1024))
Write-Host "ビデオカード:" $VideoController.Name "("$VideoMemory "GB)"

# ネットワークアダプタ
# 現在接続中のアダプタのみ
$NetworkAdapters = Get-WmiObject Win32_NetworkAdapter -Filter "netconnectionstatus = 2"
# 全アダプタ
#$NetworkAdapters = Get-WmiObject Win32_NetworkAdapter
Write-Host "ネットワークアダプタ:"
ForEach ($NetworkAdapter In $NetworkAdapters) {
  If ($NetworkAdapter.Speed -ge (1000 * 1000 * 1000)) {
    $NetworkSpeed = ($NetworkAdapter.Speed / (1000 * 1000 * 1000)).ToString() + "Gb/s"
    Write-Host " " $NetworkAdapter.Name "("$NetworkSpeed")"
  }
  Else {
    If ($NetworkAdapter.Speed -ge (1000 * 1000)) {
      $NetworkSpeed = ($NetworkAdapter.Speed / (1000 * 1000)).ToString() + "Mb/s"
      Write-Host " " $NetworkAdapter.Name "("$NetworkSpeed")"
    }
    Else {
      Write-Host " " $NetworkAdapter.Name
    }
  }
}

# ディスク
Write-Host "ドライブ:"
$LogicalDisks = Get-WmiObject Win32_LogicalDisk
ForEach ($LogicalDisk In $LogicalDisks) {
  $DiskSize = $LogicalDisk.Size / (1024 * 1024 * 1024)
  $DiskFreeSpace = $LogicalDisk.FreeSpace / (1024 * 1024 * 1024)
  Write-Host " " $LogicalDisk.DeviceID " 容量:" $DiskSize.ToString("0.00") "GB (空き領域:" $DiskFreeSpace.ToString("0.00") "GB)"
}

# OS
$OperatingSystem = Get-WmiObject Win32_OperatingSystem
Write-Host "OS:" $OperatingSystem.Caption $OperatingSystem.OSArchitecture
    この記事で書かれている製品やソフトについて
  • Windows10 Pro 64ビット
  • PowerShell 5.1.14393.206