Welcome › Forums › General PowerShell Q&A › Unexpected token in expression
- This topic has 2 replies, 2 voices, and was last updated 1 month, 3 weeks ago by
Participant.
-
AuthorPosts
-
-
November 26, 2020 at 3:16 pm #274431
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:https://blog.jbgeek.net/2020/09/18/updating-the-firmware-of-a-list-of-hpe-ilo-4-ips-via-powershell/
PowerShell1234567891011121314151617181920212223242526272829303132333435Import-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\" + $binnameNew-Item -Path $output_path -ItemType "Directory" -Force -Confirm:$false | out-nullStart-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 $7optionsCopy-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 -AppendImport-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 -
November 26, 2020 at 5:16 pm #274443
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.
-
November 27, 2020 at 1:18 am #274524
Thank you Andy!
-
-
AuthorPosts
- You must be logged in to reply to this topic.