Missing closing '}' in statement block or type definition

Lee Vaughan 1 Reputation point
2022-11-21T10:29:28.88+00:00

I am getting the following error: Missing closing '}' in statement block or type definition, but I cannot see what is wrong with the below function:

function CheckForMissingSQLPermissions {  
        param  
        (  
            $sourceRepoId,  
            $RepoPath  
        )  
      
            $CurrentTables = New-Object System.Collections.ArrayList  
            $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection("xxx")  
            $query = "SELECT DISTINCT JCBF3SettingsTables.ObjectName  
            FROM JCBF3SettingsTables INNER JOIN JCBF3Settings ON JCBF3SettingsTables.JCBF3SettingsID = JCBF3Settings.JCBF3SettingsID RIGHT OUTER JOIN  
            NRSModules ON JCBF3Settings.Value = REPLACE(NRSModules.ModuleFilename, '.exe', '')  
            WHERE (NRSModules.RepoGUID = @sourceRepoId)"  
            $command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection)  
            [void]$command.Parameters.AddWithValue("@sourceRepoId", $sourceRepoId)  
            $connection.Open()  
            $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter  
            $SqlAdapter.SelectCommand = $command  
            $DataSet = New-Object System.Data.DataSet  
            [void]$SqlAdapter.Fill($DataSet)  
      
            forEach ($r in $DataSet.tables[0].Rows) {  
                [void]$CurrentTables.Add($r.ItemArray[0])  
            }  
       
            $AllSQLTablesAndSPs = New-Object System.Collections.ArrayList  
            $query = "SELECT name FROM sys.objects WHERE type='U'  
            UNION ALL  
            SELECT SPECIFIC_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE IN ('PROCEDURE','FUNCTION')"  
            $command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection)  
            $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter  
            $SqlAdapter.SelectCommand = $command  
            $DataSet = New-Object System.Data.DataSet  
            [void]$SqlAdapter.Fill($DataSet)  
      
             forEach ($r in $DataSet.tables[0].Rows) {  
                [void]$AllSQLTablesAndSPs.Add($r.ItemArray[0])  
             }  
      
            $MissingPermissions = New-Object System.Collections.ArrayList  
            $Files = Get-ChildItem –Path $RepoPath -Recurse -Filter *.vb  
            Foreach($File in $Files)  
            {  
                $FileContent = Get-Content $File.FullName  
                forEach ($Line in $FileContent)   
                {  
                    $Words = $Line.split(" ");  
                    forEach ($Word in $Words)   
                    {  
                    if ($AllSQLTablesAndSPs.Contains($Word))  
                    {  
                        if (! $CurrentTables.Contains($Word))  
                            {  
                            [void]$MissingPermissions.Add($Word)  
                            }  
                        }  
                    }  
                }  
            }  
      
            return $MissingPermissions  
    }  
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,901 Reputation points
    2022-11-21T14:11:46.1+00:00

    The code you posted parsed ok for me in ISE. I think that the problem is in some code that you have in the script prior to this function.

    Load the entire script into ISE and use the minus signs to minimize code sections. Start with the first function. And work down.

    262657-image.png

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.