Unexpected token in expression

Hi, i run this script for updating ilo firmware, i test all strings one by one and in last string Import-Csv i get unexptected error.
Please help to understand where i did mustake.

Original script was taken from here:Updating the firmware of a list of HPE ILO 4 IPs via PowerShell – Bits & Other Bytes

Import-Module BitsTransfer
$url_zip = "https://downloads.hpe.com/pub/softlib2/software1/sc-windows-fw-ilo/p1012384589/v183793/cp044608.exe"
$binname = "ilo4_276.bin"
$output_path = "C:\TEMP\ILO4"
$output_zip = $output_path + '\cp044608.exe'
$binpath = $output_path + "\" + $binname
$iisip = "10.10.10.42"
$iispath = "\\" + $iisip + "\c$\inetpub\wwwroot\" + $binname
New-Item -Path $output_path -ItemType "Directory" -Force -Confirm:$false | out-null
Start-BitsTransfer -Source $url_zip -Destination $output_zip
$7zpath = "C:\Program Files\7-Zip\7z.exe"
$7options = "e "+ $output_zip + " " + "-o" + $output_path + " *.bin"
Start-Process -Wait -Filepath $7zpath -ArgumentList $7options
Copy-item -path $binpath -destination $iispath -force -confirm:$false

$username = "Administrator"
$password = "somepassword"
$ILOrest = "C:\Program Files\Hewlett Packard Enterprise\RESTful Interface Tool\ilorest.exe"
$ILOlist = "$output_path\ilolist.csv"
'iloip' | Out-File $ILOlist
'10.10.1.84' | Out-File $ILOlist -Append
'10.10.1.123' | Out-File $ILOlist -Append

Import-Csv $ILOlist | Foreach { $iloip = $_.iloip $args = " firmwareupdate http://" + $iisip + "/" + $binname + " --url " + $iloip + " -u " + $username + " -p " + $password Start-Process -Wait -Filepath $ILOrest -ArgumentList $args }

At line:1 char:51
+ Import-Csv $ILOlist | Foreach { $iloip = $_.iloip $args = " firmwareu ...
+                                                   ~~~~~
Unexpected token '$args' in expression or statement.
At line:1 char:174
+ ... iloip + " -u " + $username + " -p " + $password Start-Process -Wait - ...
+                                                     ~~~~~~~~~~~~~
Unexpected token 'Start-Process' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Hello Emil,

The error you are getting is because you do not have a line termination in the foreach loop on line #24.

You need to separate statements using semicolon (;), so your line #24 would look like this:

Import-Csv $ILOlist | Foreach { $iloip = $_.iloip; $args = " firmwareupdate http://" + $iisip + “/” + $binname + " --url " + $iloip + " -u " + $username + " -p " + $password; Start-Process -Wait -Filepath $ILOrest -ArgumentList $args }

Actually those 3 statements can be combined in one but I’ll leave it up to you to refactor script whenever you feel like it.

Hope that helps.

Thank you Andy!