Missing closing '}' While loop Powershell error

Kyoto Tasori 21 Reputation points
2022-05-27T21:51:42.093+00:00

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 Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,127 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 31,571 Reputation points
    2022-05-27T23:13:16.387+00:00

    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

    1 person found this answer helpful.