You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:批量启用400台PC网卡Wakeup from Shutdown功能的脚本实现

Bulk Enabling "Wakeup from Shutdown" for WOL on 400 PCs

First off, great work getting the base WOL settings configured—this last piece is tricky but totally solvable. Let's tackle how to adapt your existing PowerShell script or implement a new approach to enable that "Wakeup from Shutdown" option.

Understanding the "Wakeup from Shutdown" WMI Class

Your hunch is correct: this specific setting maps to another WMI class in the root\wmi namespace. In most cases, the target class is MSPower_DeviceWakeFromShutdown. This class controls whether the NIC can trigger a wake event when the system is fully shut down (not just sleep/hibernation).

Adapting Your Existing Script

You can extend your current loop to include this setting without rewriting the entire script. Here's how to add the logic:

foreach ($NIC in $NICs) { 
    $Errors = $false 
    Write-Host "NIC:"$NIC.Name 
    # Existing code for "Allow the computer to turn off this device"
    Write-Host "Allow the computer to turn off this device....." -NoNewline 
    $NICPowerManage = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | Where-Object { $_.instancename -match [regex]::escape ($nic.PNPDeviceID) } 
    If ($NICPowerManage.Enable -ne $TurnOffDevice) { 
        $NICPowerManage.Enable = $TurnOffDevice 
        $HideOutput = $NICPowerManage.psbase.Put() 
    } 
    If ($NICPowerManage.Enable -eq $TurnOffDevice) { 
        Write-Host "Success" -ForegroundColor Yellow 
    } else { 
        Write-Host "Failed" -ForegroundColor Red 
        $Errors = $true 
    }

    # NEW: Enable "Wakeup from Shutdown"
    Write-Host "Enabling Wakeup from Shutdown....." -NoNewline
    $WakeFromShutdown = Get-WmiObject MSPower_DeviceWakeFromShutdown -Namespace root\wmi | Where-Object { $_.instancename -match [regex]::escape($nic.PNPDeviceID) }
    if ($WakeFromShutdown -and $WakeFromShutdown.Enable -ne $true) {
        $WakeFromShutdown.Enable = $true
        $null = $WakeFromShutdown.psbase.Put()
    }
    if ($WakeFromShutdown.Enable -eq $true) {
        Write-Host "Success" -ForegroundColor Green
    } else {
        Write-Host "Failed (check if NIC supports this feature)" -ForegroundColor Red
        $Errors = $true
    }

    # Existing code for MSNdis_DeviceWakeOnMagicPacketOnly
    # ... (your existing lines here)
}

Notes on This Adaptation:

  • Some NIC manufacturers might use a custom WMI class instead of MSPower_DeviceWakeFromShutdown. If this class isn't found, check for vendor-specific classes (e.g., Intel_* or Broadcom_* in root\wmi).
  • Always test this on a single PC first to confirm the class exists and the setting sticks.

Alternative: Registry Modification (If WMI Fails)

If the WMI approach doesn't work (common with some third-party NICs), you can directly modify the registry. Most NIC advanced settings are stored under:
HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}

Each subkey (like 0000, 0001) corresponds to a network adapter. You'll need to match the NIC's PNPDeviceID to the HardwareID in these subkeys, then set a DWORD value like WakeFromShutdown to 1.

Here's a snippet to add to your script for the registry approach:

$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}"
$nicPNP = $nic.PNPDeviceID

# Find the correct NIC subkey
$nicRegKey = Get-ChildItem $regPath | Where-Object {
    (Get-ItemProperty $_.PSPath).HardwareID -contains $nicPNP
}

if ($nicRegKey) {
    Write-Host "Setting WakeFromShutdown in registry....." -NoNewline
    Set-ItemProperty -Path $nicRegKey.PSPath -Name "WakeFromShutdown" -Value 1 -Type DWord -ErrorAction SilentlyContinue
    if ((Get-ItemProperty $nicRegKey.PSPath).WakeFromShutdown -eq 1) {
        Write-Host "Success" -ForegroundColor Green
    } else {
        Write-Host "Failed" -ForegroundColor Red
        $Errors = $true
    }
} else {
    Write-Host "NIC registry key not found" -ForegroundColor Red
    $Errors = $true
}

Final Tips

  • Elevated Permissions: Ensure your script runs with administrative privileges (both WMI and registry modifications require this).
  • Batch Deployment: Use tools like Group Policy or SCCM to push this script to your 400 PCs efficiently.
  • Verify Settings: After deployment, check a few PCs manually to confirm the "Wakeup from Shutdown" option is enabled in the NIC properties.

内容的提问来源于stack exchange,提问作者david weaver

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:17:06