远程PC信息采集:如何通过PowerShell从BIOS获取CMOS时间?
Absolutely! You can totally pull BIOS/CMOS info—including that CMOS time you’re after—using PowerShell, even on remote PCs. I’ve built similar inventory automation scripts before, so let me break down exactly how to make this work for you.
First, let’s cover the prerequisites
Before diving in, make sure:
- The remote PC has WinRM (PowerShell remoting) enabled. You can flip this on with
Enable-PSRemoting -Force(needs admin rights on the target machine). - You have admin access to the remote PC.
- Your network/firewall allows WinRM traffic (default ports are 5985 for HTTP, 5986 for HTTPS).
Grab basic BIOS details first
If you need core BIOS info (like manufacturer, version, serial number), use Get-CimInstance—it’s the modern replacement for the old Get-WmiObject and works great remotely.
Local machine test:
Get-CimInstance Win32_BIOS | Select-Object Manufacturer, BIOSVersion, SerialNumber, ReleaseDate
Remote execution:
Invoke-Command -ComputerName "YourTargetPCName" -ScriptBlock { Get-CimInstance Win32_BIOS | Select-Object Manufacturer, BIOSVersion, SerialNumber, ReleaseDate }
Quick note: ReleaseDate here is when the BIOS firmware was published, not the current CMOS time—we’ll get to that next.
Get that CMOS (hardware clock) time
Windows typically syncs the system time with the CMOS hardware clock automatically, so most of the time they’ll match. But if you need to explicitly fetch the CMOS clock’s current time, here’s how to do it remotely:
Invoke-Command -ComputerName "YourTargetPCName" -ScriptBlock { # Check if the CMOS clock uses UTC (common on newer systems) $tzSettings = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation' $cmosUsesUTC = $tzSettings.RealTimeIsUniversal -eq 1 # Get the correct time based on UTC setting $cmosTime = if ($cmosUsesUTC) { [DateTime]::UtcNow } else { [DateTime]::Now } # Return a clean, readable object [PSCustomObject]@{ CMOSDateTime = $cmosTime.ToString("yyyy-MM-dd HH:mm:ss") UsesUTC = $cmosUsesUTC } }
Batch-collect from multiple PCs
If you’ve got a fleet of machines to inventory, you can scale this easily:
# List all the PCs you want to scan $computerList = @("PC-01", "PC-02", "PC-03", "Laptop-45") # Loop through each PC and collect data $inventoryResults = foreach ($pc in $computerList) { Invoke-Command -ComputerName $pc -ScriptBlock { $biosData = Get-CimInstance Win32_BIOS | Select-Object Manufacturer, BIOSVersion, SerialNumber $tzSettings = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation' $cmosUsesUTC = $tzSettings.RealTimeIsUniversal -eq 1 $cmosTime = if ($cmosUsesUTC) { [DateTime]::UtcNow } else { [DateTime]::Now } # Combine everything into one easy-to-read object [PSCustomObject]@{ ComputerName = $env:COMPUTERNAME BIOSManufacturer = $biosData.Manufacturer BIOSVersion = $biosData.BIOSVersion BIOSSerialNumber = $biosData.SerialNumber CMOSCurrentTime = $cmosTime.ToString("yyyy-MM-dd HH:mm:ss") CMOSUsesUTC = $cmosUsesUTC } } } # Export results to a CSV for easy sharing/analysis $inventoryResults | Export-Csv -Path "C:\YourInventoryFolder\BIOS_CMOS_Report.csv" -NoTypeInformation
A few quick notes to avoid headaches
- Workgroup vs Domain: In a workgroup, you’ll need to add the remote PC to your trusted hosts first:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "YourTargetPCName" -Force(replace with the PC name or IP). - Permissions: Always run PowerShell as admin when doing remote operations—otherwise you’ll hit access denied errors.
- WinRM Troubleshooting: If remote commands fail, run
Test-WSMan YourTargetPCNameto check if WinRM is reachable.
内容的提问来源于stack exchange,提问作者CodeMonkeyNumber24

