*****************************************

All Intel-provided code snippets in or attached to this blog are provided under the Intel Software Community License unless otherwise specified.

 

Any user submitted code or materials posted on this blog is supplied under license from the submitter, and should be used or downloaded in accordance with any license terms specified. Intel is not responsible for user submitted code nor warrants that it will work correctly.  If no license is provided, you should contact the submitter.

*****************************************

 

As an engineer, I work in a lab. I have a fair number of systems and laptops (of course with Intel vPro since I work with Intel vPro) I want to make my lab greener. I want to save Intel electricity. I power off my desk light when I leave. I usually power off the machines I am working on. Usually. And it is easy when I only have 2 to 3 on. But sometimes testing calls for many more. And invariably I forget some.  Is my purpose to save electricity? Sure…but I also want to automate my bench’s “poweroff and go home” procedure. Automation is awesome. And what better way to automate than using a scripting language?

 

So I decide to use the Intel vPro PowerShell module to automate my poweroff procedure.  I’m going to make a single script to turn all my machines off. This will keep me honest - I can’t forget running a single script.

 

I want to use vPro PowerShell commands to check to see if a machine is off, and if so then power it off. Yes, I could just send the poweroff command to every system…but I want to save time (I am about to leave for the day) not waiting for timeouts.

 

This outline was easy enough to make. (I’m passing in a $computername and $Credential to my script)

 

$result = Get-AMTPowerState $computerName -Credential $Credential

if ($result.'Power State ID' -eq "2") {

            invoke-amtpowermanagement $computerName -credential $Credential -operation PowerOff

} else {

write-host "$computerName was powered off so no need to call invoke-amtpowermanagement”

}

 

But what is powerstate “2” you ask? Great question.

 

I look inside the get-amtpowerstste.ps1:

                switch ($PowerState)

                {

                     2 {$StateDescription = "On (S0)"}

                     4 {$StateDescription = "Standby (S3)"}

                     7 {$StateDescription = "Hibernate (S4)"}

                     8 {$StateDescription = "Off (S5)"}

                }

 

Works great! Checks to see if power is on, and forces the system off.

 

BUT I want to give the option of a graceful in-band shutdown before calling the Intel vPro power off. So let’s expand the script to

1)     Check power state. If off – stop.

2)     Try graceful inband shut down.

3)     Check power state. If off – stop.

4)     Force system off with intel vPro.

 

 

Next steps for this script?

Capture results and output them.

Make it multi threaded.

Make the delay a parameter that is passed in.

 

But since I have a small environment and this script works well enough for me I am going to leave it the way it is.