37 lines
1.4 KiB
PowerShell
37 lines
1.4 KiB
PowerShell
# Get all physical network adapters and their WOL-related properties
|
|
$wolStatus = Get-NetAdapter -Physical | Get-NetAdapterAdvancedProperty | Where-Object {
|
|
($_.DisplayName -like '*WOL*') -or ($_.DisplayName -like '*Wake*')
|
|
}
|
|
|
|
# Function to check if WOL is disabled for any adapter
|
|
function Test-WolDisabled {
|
|
param($wolProperties)
|
|
|
|
foreach ($property in $wolProperties) {
|
|
# Check if the property is disabled or set to 0
|
|
if ($property.DisplayValue -eq 'Disabled' -or $property.DisplayValue -eq '0') {
|
|
return $true
|
|
}
|
|
}
|
|
return $false
|
|
}
|
|
|
|
# Get all physical adapters for reference
|
|
$physicalAdapters = Get-NetAdapter -Physical
|
|
|
|
# Check if WOL is disabled on any adapter
|
|
if (Test-WolDisabled -wolProperties $wolStatus) {
|
|
Write-Host "Wake on Magic Packet is disabled on one or more adapters. Enabling..."
|
|
|
|
# Enable WOL features for all physical adapters
|
|
try {
|
|
$physicalAdapters | Set-NetAdapterPowerManagement -WakeOnMagicPacket Enabled -WakeOnPattern Enabled
|
|
Write-Host "Successfully enabled Wake on Magic Packet for all physical adapters." -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host "Error enabling Wake on Magic Packet: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "Wake on Magic Packet is already enabled on all adapters." -ForegroundColor Green
|
|
} |