Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Use Get-WmiObject to enable Network Interface Card Power Management settings

$
0
0

Hi Everyone,

I have a vbscript that changes power management settings for the Network Card: this works for both local and remote computers.

I have rewritten this as a powershell script: this works when run locally but fails to update settings on remote computers. I have tried using -Credential / -Impersonation but without success.

I am assuming that Get-WmiObject will allow me to change settings on remote computers. So, how can I make this script work?

I am running the scripts from a Windows 7 Enterprise computer and trying to update Windows XP Enterprise computers on the LAN.

 

# *************************************************************************
#
# Script Name: set-WOL-Power-Management.ps1
# Version:     1.0
# Author:      John Holmes
# Date:        13th August 2009
#
# Description: Enables Network Interface Card Power Management settings:
#                1) Allow the computer to turn off this device to save power
#                2) Allow this device to wake the computer
#                3) Only allow a magic packet to wake the computer
#
#
# *************************************************************************


# Initialization Section

#Define variables used in this script
$namespace = "root\WMI"

# Functions and Filters Section


# Main Processing Section
#Clear the Windows command console screen
Clear-Host

Write-Host "`nNIC Power Management settings`n"

#Remember we can't use credentials against local machine
$cred = Get-Credential
$computer = Read-Host "Enter Machine Name"

Write-Host "Enable `"Allow the computer to turn off this device to save power`""
Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeId=0" | % {
  $strNetworkAdapterID=$_.PNPDeviceID.ToUpper()
  Get-WmiObject -class MSPower_DeviceEnable -computername $computer -credential $cred -Namespace $namespace | % {
    if($_.InstanceName.ToUpper().startsWith($strNetworkAdapterID)){
      $_.Enable = $true
      $_.Put() | Out-Null
    }
  }
}
    
    
Write-Host "Enable `"Allow this device to wake the computer`""
Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeId=0" | % {
  $strNetworkAdapterID=$_.PNPDeviceID.ToUpper()
  Get-WmiObject -class MSPower_DeviceWakeEnable -computername $computer -credential $cred -Namespace $namespace | % {
    if($_.InstanceName.ToUpper().startsWith($strNetworkAdapterID)){
      $_.Enable = $true
      $_.Put() | Out-Null
    }
  }
}
           
Write-Host "Enable `"Only allow a magic packet to wake the computer`""
Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeId=0" | % {
  $strNetworkAdapterID=$_.PNPDeviceID.ToUpper()
  Get-WmiObject -class MSNdis_DeviceWakeOnMagicPacketOnly -computername $computer -credential $cred -Namespace $namespace | % {
    if($_.InstanceName.ToUpper().startsWith($strNetworkAdapterID)){
      $_.EnableWakeOnMagicPacketOnly = $true
      $_.Put() | Out-Null
    }
  }
}
                    


Viewing all articles
Browse latest Browse all 6937

Trending Articles