Skip to content

Instantly share code, notes, and snippets.

@ted423
Created November 4, 2025 06:34
Show Gist options
  • Save ted423/5bd170391748d4bba4d952eee8ca19db to your computer and use it in GitHub Desktop.
Save ted423/5bd170391748d4bba4d952eee8ca19db to your computer and use it in GitHub Desktop.
getPCmonitorSN.bat
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
REM bat default is ANSI(gbk) set to utf-8
echo 脚本很可能需要管理员权限才能获取显示器SN
where pwsh >nul 2>nul
if %errorlevel% equ 0 (
echo "use PowerShell 7(pwsh)"
set ps=pwsh
!ps! -Command ^
"$PCInfo = Get-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber;Write-Host 'PC Serial Number:' $PCInfo; $monitorInfo = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID; if ($monitorInfo) { foreach ($monitor in $monitorInfo) { $serialNumber = [System.Text.Encoding]::ASCII.GetString($monitor.SerialNumberID); if ($serialNumber -ne 0 -and $serialNumber -ne 1) { Write-Host 'Monitor Serial Number:' $serialNumber; } } } else { Write-Host 'No monitor information found.'; };"
) else (
set ps=powershell
!ps! -NoProfile -ExecutionPolicy Bypass -Command "$PCInfo = Get-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber;Write-Host 'PC Serial Number:' $PCInfo; $monitorInfo = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID; if ($monitorInfo) { foreach ($monitor in $monitorInfo) { $serialNumber = [System.Text.Encoding]::ASCII.GetString($monitor.SerialNumberID); if ($serialNumber -ne 0 -and $serialNumber -ne 1) { Write-Host 'Monitor Serial Number:' $serialNumber; } } } else { Write-Host 'No monitor information found.'; };"
)
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment