Skip navigation

Q. What are parentheses used for in PowerShell?

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:\names.txt)

Here, the parenthetical expression, Get-Content c:\names.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.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.