Is it Power Management or Power Mis-Management?

So I hear a lot of complaints about network cards getting shut off when users leave their systems for a while.  This apparently drives our local branch techs a little crazy (who can blame them!) so I needed to find a command to add to our imaging process that would fix this issue post deployment.  Unfortunately it can’t be fixed on the image if your are using Sysprep and Mini-Setup to detect and install software drivers.  We use a single image with MDT 2010 and WDS to deploy to over 12 different models. So, while this script looks pretty simple it was a royal pain in my butt to find the solution, then only 15 minutes to write and test.  Oh well.  : /

Set NetworkAdapters = GetObject("WinMgmts://./root/Cimv2")._
ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE AdapterTypeId=0")
For Each NetworkAdapter in NetworkAdapters
  NetworkAdapterID = UCase(NetworkAdapter.PNPDeviceID)
  Set DevPwrMgtSettings = GetObject("winmgmts://./root/WMI")._
  InstancesOf("MSPower_DeviceEnable",48)
  For Each DevPwrMgtSetting in DevPwrMgtSettings
    DeviceID = UCase(Left_
    (DevPwrMgtSetting.InstanceName, Len(NetworkAdapterID)))
    If NetworkAdapterID = DeviceID Then
      DevPwrMgtSetting.Enable=False
      DevPwrMgtSetting.Put_
    End If
  Next
Next

So, breaking it down: First we get a list of network adapters [Set NetworkAdapters = GetObject(“WinMgmts://./root/Cimv2”).ExecQuery(“SELECT * FROM Win32_NetworkAdapter WHERE AdapterTypeId=0”)]. The AdapterTypeID property is used to select only ethernet adapters. Then we pull the PnPID of the adapter [NetworkAdapterID = UCase(NetworkAdapter.PNPDeviceID)] as this is how the MSPower WMI provider identifies devices. Next build our collection of devices MSPower can access [Set DevPwrMgtSettings = GetObject(“winmgmts://./root/WMI”).InstancesOf(“MSPower_DeviceEnable”,48)]. Then we make the InstanceName property of the MSPower object comparable to the NIC PnPID [DeviceID = UCase(Left(DevPwrMgtSetting.InstanceName, Len(NetworkAdapterID)))]. To make sure we are changing the power management setting on a network adapter and not some other device (USB hub, whatever) we compare the PnPID and InstanceName [If NetworkAdapterID = DeviceID Then] and then do the real work, turning off power management [DevPwrMgtSetting.Enable=False]. The final command [DevPwrMgtSetting.Put_] is extremely important, because without it your setting will not be saved!

Now save this script to a .VBS file and run it using cscript.exe: cscript \.vbs

And that’s it, how to easily turn the Power Management settings on your network adapter off (and on if you change the false to true). It is also possible to manage other settings like WOL using some other components of the MSPower WMI provider.

Advertisements

One response to “Is it Power Management or Power Mis-Management?

  1. Scott,

    That was a huge help. Trying to understand it also finally got me into learning a bit about VB, WMI and even a little bit of PS.

    One thing I’m still not quite understanding though. What exactly is this doing?:
    InstancesOf(MSPower_DeviceEnable, 48)?

    I think I understand the gist, in that the instance name is more or less the PNP ID (the less being the number that follows the last underscore), just not quite how it works… i.e. What exactly is InstancesOf, and why 48?

    Thanks,
    Bryan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s