0

I have the device ID of my drives captured into a text file and I am able to read each ID and pass into a command as a variable, but not able to pass it as $variable.bin file. I have a software, which needs certain inputs to generate the log.

Let me give an example:

  • Text File content: (random serial numbers)

    abc123124324, abc234543543, abc354354354, . .

I want to pass the above serial numbers into a command, so I used the following loop:

foreach ($line in Get-Content $filePath ) {
    Write-Host "Generating info for $line"
    C:\Users\Administrator\Desktop\software.exe -K -o sup -f **${line}.bin** -n $line
    }

=== I need to pass each serial number as serialnumber.bin, but its giving an error as its not able to add .bin

Note: For another command (which does not require the use of .bin) the below code works fine:

C:\Users\Administrator\Desktop\software.exe -K ${line}_log.zip -n $line

Not sure how to add a .bin extension. Please help!!

Raven
  • 3
  • 2
  • 2
    Surround in quotes `"$line.bin"` – Daniel Jan 15 '23 at 07:29
  • Hi @Raven, what the double starts (**) are meaning. Stars are not allowed in file names. Ca you give the error you encounter. – JPBlanc Jan 15 '23 at 07:30
  • You're looking for `"${line}.bin"`, as @Daniel points out. Without the enclosing `"..."`, PowerShell treats it as a _property access_, i.e. it looks for property `.bin` on whatever object is stored in variable `${line}`. See the linked duplicate for details. – mklement0 Jan 15 '23 at 18:33
  • @JPBlanc, I think the `**` were just for emphasis, to highlight the place in the code where the problem occurs. – mklement0 Jan 15 '23 at 18:36

0 Answers0