Drew Furgiuele writes a bit of Powershell to control power plan settings and expands upon this one-liner:
It’s a classic one-liner, but if you’re not used to reading it I’ll break it down for you. First, we useGet-ChildItem to return a list of registered servers in our central management server (named PRO-CM-SQL in my example). This returns a series of objects that lists all the registered names on the central management server in each directory, so we need to filter out the directory names with a Where-Object (objects that don’t have a “mode” value of “d” for directory). Once we have our list, we just select the names ( Select-Object ). Then we pipe the list of names over to a ForEach-Object and execute the script each time. Finally, we tack on a Export-CSV cmdlet to output the results to an easy to read file we can open in Excel (or notepad, or whatever).
Our script also doesn’t control output, so you leave that up to the user. They can put it on the screen or pipe it to a file. And that’s an important style point: never put your users on rails. You may like output one way, but someone else may not. Just think of the next person.Because some day you might be that next person.
This is a good post if you need to figure out how to find your servers’ current power settings, but a great post if you want to think about how to write helpful Powershell scripts.