Using Powershell remoting with Powercfg to query/update power settings

I seem to be the guy in work that people come ask to perform multiple actions over many machines. Why is this? Because I am my work’s Powershell guy, that’s why!

Today I was asked to update some servers which were added to some of our branch offices. Good job I made sure these boxes supported Powershell remoting before they left the workshop.

With remoting I can easily perform a quick remote command, or perform advanced actions on multiple machines.

Powershell allows a few ways to perform remoting.

You can use Enter-PSSession to create a session. Or you could use the invoke-command cmdlet. This is what I used.

Invoke-command –computername ****** –scriptblock {command line action}

With this one liner I was able to invoke a command on 50 servers and perform any action that can be performed at the command line.

So to invoke a powercfg command within multiple sessions I typed the following command

Invoke-Command -ComputerName (Get-Content c:servers.txt) -ScriptBlock {powercfg /query}

This command does the following:

  • Calls Invoke-Command with the computername parameter.
  • Gets multiple computer names from a text file using Get-Content.
  • Then uses the scriptblock parameter to invoke the command.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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

%d bloggers like this: