gwblok / garytown

GaryTown Scripts, Downloads, Etc
251 stars 76 forks source link

HPIA-PR-Detect.ps1 - The Try statement is missing its Catch or Finally block. The string is missing the terminator: ". Missing closing '}' in statement block or type definition. #14

Closed Brad-Dale closed 7 months ago

Brad-Dale commented 8 months ago

When running the HPIA-PR-Detect.ps1 script in PowerShell or VS Code it results in the following errors:

 PS C:\git\source\internal> . 'C:\Scripts\HPIA\HPIA-PR-Detect.ps1'
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:94 char:18
+                 }
+                  ~
The Try statement is missing its Catch or Finally block.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:314 char:2 
+ }
+  ~
The Try statement is missing its Catch or Finally block.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:327 char:36
+     Write-Host "Trigger Remediation"
+                                    ~
The string is missing the terminator: ".
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:315 char:6 
+ else {
+      ~
Missing closing '}' in statement block or type definition.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:84 char:35
+     if ($HPIAIsCurrent -eq $false){
+                                   ~
Missing closing '}' in statement block or type definition.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:34 char:22
+ Function Install-HPIA{
+                      ~
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingCatchOrFinally

Similar issue also occurs for other scripts. VS Code raises the below for lines 310 - 312 and 316 - 318.

The character U+2013 "–" could be confused with the ASCII character U+002d "-", which is more common in source code.

Replacing as recommended doesn't resolve.

gwblok commented 7 months ago

Thanks, I've run into this in the past when uploading scripts to GitHub, copy / paste issue or something.
Thanks for pointing it out. I've done a find / replace, and it should be resolved now.

Please feel free to open these issues as you find them. Much appreciated.
Sorry for the delay, I didn't notice the issue until this weekend.

Brad-Dale commented 7 months ago

Thanks Gary,

Unfortunately similar issue popped up with the new version, in different lines.

At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:326 char:36
+     Write-Host "Trigger Remediation"
+                                    ~
The string is missing the terminator: ".
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:218 char:9
+         {
+         ~
Missing closing '}' in statement block or type definition.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:187 char:9
+     try {
+         ~
Missing closing '}' in statement block or type definition.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:329 char:1
+ 
The Try statement is missing its Catch or Finally block.
At C:\Scripts\HPIA\HPIA-PR-Detect.ps1:144 char:19
+ Function Run-HPIA {
+                   ~
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Find & replacing would sometimes work others not, but got there in the end. I'll raise another issue for what I encountered next.