Newbie Stuck - LWPS3inMoL Parenthetical CMDs

If this post is not appropriate for this forum, kindly direct me to other forums.

I do not know a single programming language and struggle with with DOS batch files. So I must sincerely state that your step by step, chapter by chapter explanations in LWPS3inMoL are stellar. You book is teaching an old dog new tricks.

However I am stuck. PS errors out when evaluating the stuff in parens in the example below (lifted from the book). When I type in the example command line, the PS_ISE highlights the left and right parens. It seems like it is trying to tell me something.

Learn Windows Powershell 3 in a Month of Lunches - SecondEdition
9.6 Parenthetical Commands (Page 111)

PS C:> Get-WmiObject -class win32_BIOS -ComputerName (Get-Content .\computers.txt)
Get-WmiObject : Cannot validate argument on parameter ‘ComputerName’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At line:1 char:47

  • Get-WmiObject -class win32_BIOS -ComputerName (Get-Content .\computers.txt)
  •                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidData: (:slight_smile: [Get-WmiObject], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
      PS C:>


That’s odd. There’s nothing wrong with the syntax or the use of parentheses there. If the ISE is simply highlighting the parentheses (not putting red squiggly lines underneath them), that’s a normal feature. Whenever your cursor is placed directly before an opening brace or after a closing brace, the ISE highlights them both, to help you read the code more quickly.

I would expect to see that error if there were no computers.txt file in the current working directory when you executed the script, or if the file contained no data.

Dave’s right. PowerShell ISE and other editors highlight matching brackets to give you a visual cue so that you can match brackets more easily. It’s a very helpful feature when using multiple sets of brackets nested within one another.

The error you receive indicates that PowerShell was unable to find a computers.txt file in your current directory when you ran that script. If you modify the script to use an absolute path to computers.txt (i.e. C:\MyFolder\computers.txt instead of .\computers.txt), or if you change your current working directory to the directory where computers.txt is stored, then it should run just fine.

I agree that it looks like it can’t read the file. My 2 guesses as to why that is are:

  1. You created and renamed a new text document but have the extension hidden so you have ended up with a file called computers.txt.txt. Do
    Get-Childitem C:\
    to double check the name.
  2. You haven't got the computers.txt file in the root of the c drive (as that is where you are running from in your example).
  3. Read permissions is an outside guess, but i really doubt it is that.

Thanks for the quick response from all.

I -knew- PS was trying to tell me something with the highlighted parens.

The commments regarding my computers.txt file caused me to delete and recreate the file with notepad.
Now my command works with the parens evaluating correctly and giving a string to -computername that it can deal with.

Many thanks to all for sharing your knowledge.