question

KyotoTasori-6918 avatar image
0 Votes"
KyotoTasori-6918 asked MotoX80 commented

Missing closing '}' While loop Powershell error

My program is simple and I keep getting the error

while ($true) {
    $shell = Read-Host -Prompt "<";
    if (($shell -Split " ")[0] -eq "clear") {
        Clear-Host;
        if (($shell -Split " ")[1..1] -eq "-echo") {
            Write-Host "0" -ForegroundColor Blue;
        }
    }
    #########.
    if (($shell -Split " ")[0] -eq "math") {
        
    }
    Output/Variable Management
    $shell = $null;
}


Exception calling "Create" with "1" argument(s): "At line:1 char:15
+ while ($true) { $shell = Read-Host -Prompt "<"; if (($shell - ...
+ ~
Missing closing '}' in statement block or type definition."
At C:\Users\epicv\Tasori OS\homeHost.ps1:26 char:5
+ Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ParseException

windows-serverwindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
1 Vote"
MotoX80 answered MotoX80 commented

Missing closing '}' in statement block or type definition."
At C:\Users\epicv\Tasori OS\homeHost.ps1:26 char:5
+ Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content " ...



There is no Invoke-Command in the code that you posted. Did you only post a part of the script?


It's a little hard to see, but if you test your code in Powershell_ISE, when you click on a bracket, ISE will highlight (grey background) it's matching bracket. That should help you "see" where you need to add a bracket.


206333-capture.png



capture.png (30.5 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes this is only part of the script so ignore that part of the error

0 Votes 0 ·
MotoX80 avatar image MotoX80 KyotoTasori-6918 ·

Line 13 is invalid. Should that be a comment?

 while ($true) {
     $shell = Read-Host -Prompt "<";
     if (($shell -Split " ")[0] -eq "clear") {
         Clear-Host;
         if (($shell -Split " ")[1..1] -eq "-echo") {
             Write-Host "0" -ForegroundColor Blue;
         }
     }
     #########.
     if (($shell -Split " ")[0] -eq "math") {
            Write-Host " A math request" -ForegroundColor Yellow;
     }
     # Output/Variable Management
     $shell = $null;
 }

0 Votes 0 ·