Q. What are parentheses used for in PowerShell?

Don Jones

April 30, 2010

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. In PowerShell, parentheses are used to group expressions. If you’re looking at a complicated command that includes parentheses, there’s an easy trick to figuring out what’s going on. Consider this example:

Get-WmiObject Win32_BIOS -computerName (Get-Content c:ames.txt)

Here, the parenthetical expression, Get-Content c:ames.txt, will be executed first. The entire parenthetical expression will be replaced by whatever the expression resulted in. For example, if Get-Content is reading a text file that contains a bunch of computer names, the new command will be something like this:

Get-WmiObject Win32_BIOS -computerName server1,server2,server3,server4

Those computer names—the results of whatever was happening inside the parentheses—will become the set of values that is passed to the -computerName parameter. In fact, you’ll often see parentheses used to execute one command and pass its results to a parameter of another command.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like