When posting code, please use the "Code Sample" icon (or Control+K) so the code is readable and to avoid the system from doing stupid things like removing the "_" after a "$" character. We'd all appreciate it!
Your problem is that immediately after the line 'Remove-ItemProperty -Path $WinlogonPath -Name "DefaultPassword" -Force' you have a "}" that terminates the "Try" block, but then you have code between that "}" and the beginning of the "Catch" block. I'd guess that the incorrectly placed "}" should be removed and the intervening code should become part of the "Try" block.
Using indentation in your code would make that pretty obvious, and using an editor (such as VS Code) that flags mismatched braces, parenthesis, quotes, etc. would make your coding a lot easier.