{"id":13041,"date":"2011-08-11T00:01:00","date_gmt":"2011-08-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/08\/11\/configure-a-network-adapter-to-wake-a-computer-via-powershell\/"},"modified":"2011-08-11T00:01:00","modified_gmt":"2011-08-11T00:01:00","slug":"configure-a-network-adapter-to-wake-a-computer-via-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/configure-a-network-adapter-to-wake-a-computer-via-powershell\/","title":{"rendered":"Configure a Network Adapter to Wake a Computer Via PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to use Windows PowerShell to configure a remote computer&#8217;s network adapter to wake the computer.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hey, Scripting Guy! At work, we have been trying to get our automation solution put into place. One problem is that on many of the computers, the network adapter is not configured to allow it to wake up the machine. This means that when someone shuts down the computer in the evening, that is it until the next day. I would like to be able to do maintenance at night when the users have gone home, but to do so, I need to be able to wake up the computer. I found an article on the Internet, but basically the article talked about hacking the registry, and I did not feel like I could trust the article. Can Windows PowerShell configure a computer&rsquo;s network card to allow it to wake up the computer?<\/p>\n<p>&mdash;TS<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hello TS,<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. One thing to keep in mind about Windows PowerShell is that it can only do what is available. In other words, if no mechanism exists for automating a particular problem, Windows PowerShell will not be able to automate a solution. Windows PowerShell can certainly make working with registry keys easier because of the existence of the registry provider, and it can make working with WMI classes easier as well. However, if the underlying technology does not expose the functionality, we are out of luck.<\/p>\n<p>TS, in this particular case, I am not certain you are out of luck. I was looking over my list of WMI classes that have settable properties and implemented methods, and I ran across the <b>MSPower_DeviceWakeEnable<\/b> WMI class. This particular WMI class exists in the Root\\WMI namespace, and is not documented on MSDN. Because the WMI class is not documented, this means that it is not supported. It does not mean that it will not work, but that it is not supported. As a matter of a fact, it does not work on my Windows 7 Ultimate 64-bit desktop computer; I believe that is because I have a custom network adapter card driver that supports port teaming for better throughput.<\/p>\n<p>The WMI class does work on my 32-bit Windows 2008 server, which is using an inbox network card driver. Because the class is not documented, it means that I cannot tell you if the class exists on Windows XP or Windows Server 2003. I know it exists on Windows Server 2008 R2, Windows Server 2008, and Windows 7.<\/p>\n<p>TS, I am going to show you how to use the <b>MSPower_DeviceWakeEnable<\/b> WMI class to enable the network card to wake the machine. If the technique does not work on all your devices, there is nothing I can do&mdash;the class is unsupported (although you might be able to use the <b>powercfg<\/b> utility to configure your network cards to wake up the computer).<\/p>\n<p>The first thing I need to do is to store credentials for my remote WMI connection. Remember, I am working against a remote server. I use the <b>Get-Credential<\/b> cmdlet to retrieve the credentials for the remote computer, and I store the returned credential object in the <b>$cred<\/b> variable. This is shown here:<\/p>\n<p style=\"padding-left: 30px\">$cred = Get-Credential nwtraders\\administrator<\/p>\n<p>Next, I use WMI and the <b>Get-WmiObject<\/b> cmdlet to look for a network card on the remote server that is <b>netenabled<\/b><i>.<\/i> This property of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394216(VS.85).aspx\"><b>Win32_NetworkAdapter<\/b> class<\/a> should return <b>True<\/b> only if the network interface is enabled. If there are multiple network cards that are enabled, you might want to query for the <b>NetConnectionStatus<\/b> of 2 (means that it is connected). If you are still having difficulity finding the correct network adapter, you might want to try the <b>netconnectionid<\/b><i> <\/i>property. That is the name of the connection (for example &ldquo;Local Area Connection&rdquo;), and if you have named all your network adapters the same, it will be easy to pick them up with this property.<\/p>\n<p>When I query the <b>netenabled<\/b> property on my remote server, only one network adapter is returned. The command and associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gwmi win32_networkadapter -filter &#8220;netenabled = &#8216;true'&#8221; -cn dc1 -cred $cred<\/p>\n<p style=\"padding-left: 30px\">ServiceName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : E100B<\/p>\n<p style=\"padding-left: 30px\">MACAddress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 00:07:E9:7C:A7:5F<\/p>\n<p style=\"padding-left: 30px\">AdapterType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Ethernet 802.3<\/p>\n<p style=\"padding-left: 30px\">DeviceID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Intel(R) PRO\/100 VE Network Connection<\/p>\n<p style=\"padding-left: 30px\">NetworkAddresses :<\/p>\n<p style=\"padding-left: 30px\">Speed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 100000000<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>Now I repeat the above command, and store the returned WMI object in a variable named <b>$nic<\/b>. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">$nic= gwmi win32_networkadapter -filter &#8220;netenabled = &#8216;true'&#8221; -cn dc1 -cred $cred<\/p>\n<p>I next query the <b>MSPower_DeviceWakeEnable<\/b> WMI class to see what type of date it returns. The WMI class resides in the Root\\WMI namespace, so I need to specify the <i>namespace <\/i>parameter when making the query. I am still working on a remote machine, so I also specify the <i>computername<\/i> (alias is <i>cn<\/i>) and the <i>credential<\/i> (shortened to <i>cred<\/i>) parameters. The command and associated output appear here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi -cn dc1 -cred $cred<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">__GENUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2<\/p>\n<p style=\"padding-left: 30px\">__CLASS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable<\/p>\n<p style=\"padding-left: 30px\">__SUPERCLASS&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__DYNASTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__RELPATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\VEN_8086&amp;DEV_105<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&amp;SUBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">__PROPERTY_COUNT : 3<\/p>\n<p style=\"padding-left: 30px\">__DERIVATION&nbsp;&nbsp;&nbsp;&nbsp; : {MSPower}<\/p>\n<p style=\"padding-left: 30px\">__SERVER&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: DC1<\/p>\n<p style=\"padding-left: 30px\">__NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : root\\wmi<\/p>\n<p style=\"padding-left: 30px\">__PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : \\\\DC1\\root\\wmi:MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\V<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EN_8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;<\/p>\n<p style=\"padding-left: 30px\">Active&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">Enable&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: True<\/p>\n<p style=\"padding-left: 30px\">InstanceName&nbsp;&nbsp;&nbsp;&nbsp; : PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\4&amp;1c660dd6&amp;0&amp;40<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F0_0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">__GENUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2<\/p>\n<p style=\"padding-left: 30px\">__CLASS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable<\/p>\n<p style=\"padding-left: 30px\">__SUPERCLASS&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__DYNASTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__RELPATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable.InstanceName=&#8221;ACPI\\\\PNP0303\\\\4&amp;1506<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bb2e&amp;0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">__PROPERTY_COUNT : 3<\/p>\n<p style=\"padding-left: 30px\">__DERIVATION&nbsp;&nbsp;&nbsp;&nbsp; : {MSPower}<\/p>\n<p style=\"padding-left: 30px\">__SERVER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : DC1<\/p>\n<p style=\"padding-left: 30px\">__NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : root\\wmi<\/p>\n<p style=\"padding-left: 30px\">__PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : \\\\DC1\\root\\wmi:MSPower_DeviceWakeEnable.InstanceName=&#8221;ACPI\\\\<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PNP0303\\\\4&amp;1506bb2e&amp;0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">Active&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">Enable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"padding-left: 30px\">InstanceName&nbsp;&nbsp;&nbsp;&nbsp; : ACPI\\PNP0303\\4&amp;1506bb2e&amp;0_0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The <b>InstanceName<\/b><i> <\/i>properties look weird, but they also look familiar. They look like the <b>PNPDeviceID<\/b><i> <\/i>property from the <b>Win32_NetworkAdapter<\/b> WMI class. I can therefore use the <b>PNPDeviceID<\/b><i> <\/i>property value from my network adapter and filter out only a matching instance from the <b>MSPower_DeviceWakeEnable<\/b> WMI class. So I take the <b>PNPDeviceID<\/b> property value and attempt to use it in a <b>Where-Object<\/b> command. Unfortunately, an error results. The command and associated output are shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi | where {$_.instancena<\/p>\n<p style=\"padding-left: 30px\">me -match $nic.PNPDeviceID }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Bad argument to operator &#8216;-match&#8217;: parsing &#8220;PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_015710<\/p>\n<p style=\"padding-left: 30px\">28&amp;REV_02\\4&amp;1C660DD6&amp;0&amp;40F0&#8243; &#8211; Unrecognized escape sequence \\V..<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:82<\/p>\n<p style=\"padding-left: 30px\">+ gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi | where {$_.instancename -m<\/p>\n<p style=\"padding-left: 30px\">atch &lt;&lt;&lt;&lt;&nbsp; $nic.PNPDeviceID }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidOperation: (:) [], RuntimeException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : BadOperatorArgument<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Bad argument to operator &#8216;-match&#8217;: parsing &#8220;PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_015710<\/p>\n<p style=\"padding-left: 30px\">28&amp;REV_02\\4&amp;1C660DD6&amp;0&amp;40F0&#8243; &#8211; Unrecognized escape sequence \\V..<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:82<\/p>\n<p style=\"padding-left: 30px\">+ gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi | where {$_.instancename -m<\/p>\n<p style=\"padding-left: 30px\">atch &lt;&lt;&lt;&lt;&nbsp; $nic.PNPDeviceID }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidOperation: (:) [], RuntimeException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : BadOperatorArgument<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Bad argument to operator &#8216;-match&#8217;: parsing &#8220;PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_015710<\/p>\n<p style=\"padding-left: 30px\">28&amp;REV_02\\4&amp;1C660DD6&amp;0&amp;40F0&#8243; &#8211; Unrecognized escape sequence \\V..<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:82<\/p>\n<p style=\"padding-left: 30px\">+ gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi | where {$_.instancename -m<\/p>\n<p style=\"padding-left: 30px\">atch &lt;&lt;&lt;&lt;&nbsp; $nic.PNPDeviceID }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidOperation: (:) [], RuntimeException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : BadOperatorArgument<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Bad argument to operator &#8216;-match&#8217;: parsing &#8220;PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_015710<\/p>\n<p style=\"padding-left: 30px\">28&amp;REV_02\\4&amp;1C660DD6&amp;0&amp;40F0&#8243; &#8211; Unrecognized escape sequence \\V..<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:82<\/p>\n<p style=\"padding-left: 30px\">+ gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi | where {$_.instancename -m<\/p>\n<p style=\"padding-left: 30px\">atch &lt;&lt;&lt;&lt;&nbsp; $nic.PNPDeviceID }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : InvalidOperation: (:) [], RuntimeException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : BadOperatorArgument<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The problem, it seems, is that the <b>PNPDeviceID<\/b><i> <\/i>property contains characters that have a meaning in a regular expression. The <b>PNPDeviceID<\/b><i> <\/i>is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $nic.pnpdeviceid<\/p>\n<p style=\"padding-left: 30px\">PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\4&amp;1C660DD6&amp;0&amp;40F0<\/p>\n<p>The special characters need to be escaped before submitting to the Regex engine. This could be a tedious problem. But, then I remembered there is an <b>escape<\/b> method from the <b>REGEX<\/b> class. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.text.regularexpressions.regex.escape.aspx\"><b>Regex<\/b><strong>.Escape<\/strong> method<\/a> is documented on MSDN and is easy to use. It will escape any invalid character in a string, and permit easy use of that string. This is exactly what is needed here. I place the call to the <b>escape<\/b> method just in front of the <b>PNPDeviceID<\/b> property. I store the returned object in a variable called <b>$nicPower<\/b> and I query the variable to ensure I contain the proper network adapter. Notice that the status of the <b>enable<\/b> property is set to <b>false<\/b>. The command and associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $nicPower = gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi -cn dc1 -cred $cred | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $nicPower<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">__GENUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2<\/p>\n<p style=\"padding-left: 30px\">__CLASS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable<\/p>\n<p style=\"padding-left: 30px\">__SUPERCLASS&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__DYNASTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower<\/p>\n<p style=\"padding-left: 30px\">__RELPATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\VEN_8086&amp;DEV_105<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&amp;SUBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">__PROPERTY_COUNT : 3<\/p>\n<p style=\"padding-left: 30px\">__DERIVATION&nbsp;&nbsp;&nbsp;&nbsp; : {MSPower}<\/p>\n<p style=\"padding-left: 30px\">__SERVER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : DC1<\/p>\n<p style=\"padding-left: 30px\">__NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : root\\wmi<\/p>\n<p style=\"padding-left: 30px\">__PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : \\\\DC1\\root\\wmi:MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\V<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EN_8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;<\/p>\n<p style=\"padding-left: 30px\">Active&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">Enable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"padding-left: 30px\">InstanceName&nbsp;&nbsp;&nbsp;&nbsp; : PCI\\VEN_8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\4&amp;1c660dd6&amp;0&amp;40<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F0_0<\/p>\n<p>Now, all I need to do is to change the value of the <b>Enable<\/b> property from <b>False<\/b> to <b>True<\/b>. After I have done that, I need to call the <b>Put<\/b> method from the base WMI object so that I write the changes back to the WMI database. These two commands and their associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $nicPower.Enable = $true<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $nicPower.psbase.Put()<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : \\\\dc1\\root\\wmi:MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\VEN_<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8086&amp;DEV_1050&amp;SUBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">RelativePath&nbsp; : MSPower_DeviceWakeEnable.InstanceName=&#8221;PCI\\\\VEN_8086&amp;DEV_1050&amp;S<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UBSYS_01571028&amp;REV_02\\\\4&amp;1c660dd6&amp;0&amp;40F0_0&#8243;<\/p>\n<p style=\"padding-left: 30px\">Server&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : dc1<\/p>\n<p style=\"padding-left: 30px\">NamespacePath : root\\wmi<\/p>\n<p style=\"padding-left: 30px\">ClassName&nbsp;&nbsp;&nbsp;&nbsp; : MSPower_DeviceWakeEnable<\/p>\n<p style=\"padding-left: 30px\">IsClass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"padding-left: 30px\">IsInstance&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">IsSingleton&nbsp;&nbsp; : False<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>It takes a reboot for the changes to take effect. Because I am working remotely and using WMI, I decide to use the <b>Reboot<\/b><i> <\/i>method from the <b>Win32_OperatingSystem<\/b> WMI class. When calling the <b>Reboot<\/b> method from <b>Win32_OperatingSystem<\/b>, it seems to be a bit confusing. For example, if I use the <b>[WMICLASS]<\/b> type accelerator, the <b>Reboot<\/b> and <b>Shutdown<\/b> methods appear as shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; [wmiclass]&#8221;Win32_OperatingSystem&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; NameSpace: ROOT\\cimv2<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Methods<\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Properties<\/span><\/p>\n<p style=\"padding-left: 30px\">Win32_OperatingSystem &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Reboot, Shutdown&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {BootDevice, BuildN&#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>But, when I attempt to use the <b>Invoke-WmiMethod<\/b> cmdlet to reboot the computer, an error occurs. The error is shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2313.HSG-8-11-11-01.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of error shown when attempting to use Invoke-WmiMethod to reboot computer\" alt=\"Image of error shown when attempting to use Invoke-WmiMethod to reboot computer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2313.HSG-8-11-11-01.png\" \/><\/a><\/p>\n<p>Before I actually reboot the system, I connect via Remote Desktop and view the status of the network adapter. As shown in the following figure, it is not configured to allow the device to wake the computer.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5025.HSG-8-11-11-02.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of network adapter not configured to allow device to wake computer\" alt=\"Image of network adapter not configured to allow device to wake computer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5025.HSG-8-11-11-02.png\" \/><\/a><\/p>\n<p>Okay, I have verified the baseline configuration. Now I need to figure out why my reboot command did not work. The reason it failed is because the <b>Reboot<\/b> method is an instance method, not a static method. The easiest way to reboot the machine is to use the <b>Get-WmiObject<\/b> cmdlet, and call the method directly from the resulting object. This command and its associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; (gwmi win32_operatingsystem -CN dc1 -cred $cred).reboot()<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">__GENUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2<\/p>\n<p style=\"padding-left: 30px\">__CLASS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : __PARAMETERS<\/p>\n<p style=\"padding-left: 30px\">__SUPERCLASS&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">__DYNASTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : __PARAMETERS<\/p>\n<p style=\"padding-left: 30px\">__RELPATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">__PROPERTY_COUNT : 1<\/p>\n<p style=\"padding-left: 30px\">__DERIVATION&nbsp;&nbsp;&nbsp;&nbsp; : {}<\/p>\n<p style=\"padding-left: 30px\">__SERVER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">__NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">__PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">ReturnValue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>After waiting an indeterminable amount of time, the remote domain controller is back up and running. I connect once again with Remote Desktop to see if my changes actually took. As shown in the following figure, it worked.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5047.HSG-8-11-11-03.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of change having been applied\" alt=\"Image of change having been applied\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5047.HSG-8-11-11-03.png\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The complete sequence of commands could be placed easily in a single script and used to perform this configuration change in an automated fashion. Here are the commands:<\/p>\n<p style=\"padding-left: 30px\"><strong>EnableNicToWakeMachine.ps1<\/strong><\/p>\n<p style=\"padding-left: 30px\">$cred = Get-Credential nwtraders\\administrator<\/p>\n<p style=\"padding-left: 30px\">$nic= gwmi win32_networkadapter -filter &#8220;netenabled = &#8216;true'&#8221; -cn dc1 -cred $cred<\/p>\n<p style=\"padding-left: 30px\">$nicPower = gwmi MSPower_DeviceWakeEnable -Namespace root\\wmi -cn dc1 -cred $cred |<\/p>\n<p style=\"padding-left: 30px\">&nbsp; where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }<\/p>\n<p style=\"padding-left: 30px\">$nicPower.Enable = $true<\/p>\n<p style=\"padding-left: 30px\">$nicPower.psbase.Put()<\/p>\n<p style=\"padding-left: 30px\">(gwmi win32_operatingsystem -CN dc1 -cred $cred).reboot()<\/p>\n<p>&nbsp;<\/p>\n<p>TS, that is all there is to using WMI to set the ability of a NIC to wake up a computer. This also concludes WMI Method Week. Join us tomorrow when we have a guest blog article by Robert Robelo.<\/p>\n<p>&nbsp;<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell to configure a remote computer&#8217;s network adapter to wake the computer. &nbsp; Hey, Scripting Guy! At work, we have been trying to get our automation solution put into place. One problem is that on many of the computers, the network adapter is not configured to allow it to [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[36,37,31,173,3,4,45,6],"class_list":["post-13041","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-client-side-management","tag-networking","tag-operating-system","tag-power-management","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to configure a remote computer&#8217;s network adapter to wake the computer. &nbsp; Hey, Scripting Guy! At work, we have been trying to get our automation solution put into place. One problem is that on many of the computers, the network adapter is not configured to allow it to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13041"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13041\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=13041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}