Calling a vPro Cmdlet from a cmd line

So, I had an interesting situation where I needed to call one of my vPro PowerShell Module AMT Cmdlets...from a command line.

Lucky for me there is a powershell command and it lets me pass in a command! Perfect - almost.

I am loading the credential $amtcred from the AMT secure storage(see another blog of mine) as part of my powershell profile. I don't have to worry about typing in my credentials every time I start a shell.

Now I run the following command

C:>powershell -command "& {import-module intelvpro; $amtcred = read-amtcredential; invoke-amtpowermanagement -credential $amtcred -operation PowerOn}"

This works! After I'm prompted for the computername though.

calling with no variables.png

But I would like to pass in a computername!

So I try calling a ps1 script:

C:>powershell -file c:testscript.ps1

I can't figure out a way to pass a varibale in. Oh well - so I decide to use a batch file - which I can pass a variable in!

1) Create a bat file, let’s say “Power on Machine.bat”
2) In this file, add one line

powershell -command "& {import-module intelvpro; $amtcred = read-amtcredential; invoke-amtpowermanagement %* -credential $amtcred -operation PowerOn}"

3) Save file

batch file.png

Notice the %*? It works!

In a command window, type

"c:power on machine.bat"

calling batch file.png

Nice.Calling a cmdlet from a cmd line with a variable!