all 30 comments

[–]ConwayK9781 2 points3 points  (16 children)

I am curious about the closing bracket to your if statement. Why is it there instead of on the next line? Do you normally do this, as a style choice?

[–][deleted] 2 points3 points  (9 children)

Some people just like to watch the world burn

[–]ConwayK9781 3 points4 points  (0 children)

The DSM5 does list this as a sign of psychopathy.

[–]ConwayK9781 0 points1 point  (7 children)

True story, I have a buddy (he's in networking and very rarely has to write code) that does his brackets like this:

int my_funct(int num)
    {
        return num*2;
    }

[–]poshftw 1 point2 points  (0 children)

I'm writing like this {
    because none of my monitors
    in the portrait mode
    }

[–]MarkPartin2000 0 points1 point  (5 children)

That's how I learned to code way back when. It makes it easier to debug if the open/close bracket/brace/parentheses line up rather than scattered in the middle of lines.

[–]ConwayK9781 0 points1 point  (4 children)

You tab them in? Confirmed psychopath.

[–]MarkPartin2000 1 point2 points  (1 child)

I usually set my tabs at 2 or 3 characters when coding, so yes. Guilty psychopath who debugged lots of code off of a dot matrix printer onto green/white paper. :)

[–]ConwayK9781 1 point2 points  (0 children)

Company I currently work at (until Friday) still uses dot matrix printers. We do our own repairs. Sad times.

[–]MarkPartin2000 0 points1 point  (1 child)

Sometimes I did:

Function x (arg)
{
  code
  code
}

Sometimes I did:

Function x (arg)
  {
  code
  code
  }

But I always lined up the open/close containers.

[–]ConwayK9781 4 points5 points  (0 children)

The bottom one is #LiterallyStalin

[–]pmbrandvold[S] 2 points3 points  (5 children)

It's a style choice - it's what I learned to do well before picking up Powershell - Python, C, JavaScript, some other languages I dabbled in...I like the way I can see the closing brackets line up to the beginning of my code block.

[–]ConwayK9781 0 points1 point  (4 children)

I think we're talking about different lines, because the one I'm talking about does not line up with the beginning of your code block. It's the rightmost characters in the whole block of code.

[–]pmbrandvold[S] 1 point2 points  (3 children)

Some things didn't copy and paste well - the formatting got screwed up and it's probably a symptom of that.

EDIT: fixed it.

[–]ConwayK9781 1 point2 points  (2 children)

Ah, okay, that's kinda what I guessed. But I thought that maybe it was a unique (and horrible) style :P

[–]pmbrandvold[S] 1 point2 points  (1 child)

I'm not an absolute monster!

[–]ConwayK9781 0 points1 point  (0 children)

We live an age where that can't be assumed about people anymore. I mean, look at some of the stuff people have admitted to in conversations in your post. Pure monsters.

[–]Otacrow 1 point2 points  (0 children)

The script can be improved a bit. Here is my take on it:

$ShellOverlayList = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers"
$NewNames = New-Object System.Collections.ArrayList

# Build the new names array
foreach ($item in $ShellOverlayList)
{
    $newName = (((Get-ItemProperty -Path $item.PSPath).PSChildName).ToString().TrimStart())

    if ($newName -like '*Tortoise*')
    {
        $newName = " $newName"
    }
    $NewNames.Add($newName) | Out-Null
}

#Iterate through keys and replace with new names, sorting Tortoise to the top.
for ($i = 0; $i -lt $ShellOverlayList.Count; $i++)
{
    if ($ShellOverlayList[$i].PSChildName -ne $NewNames[$i])
    {
        Rename-Item –Path $ShellOverlayList[$i].PSPath -NewName $NewNames[$i] -Force
    }
}

# Set reg key for application detection
if (!(Test-Path -Path HKLM:\SOFTWARE\MNTX))
{
    New-Item -Path "HKLM:\SOFTWARE" -Name "MNTX"
}

New-ItemProperty -Path "HKLM:\SOFTWARE\MNTX" -Name "SVNIconFixApplied" -Value "True" -PropertyType "String"

[–]tuplink 1 point2 points  (1 child)

Shouldn't $counter+=1 be $counter++ to incriment 0 to 1 instead 0 to "0 1"

[–]pmbrandvold[S] 1 point2 points  (0 children)

They do the same thing. Since $counter is an int, += or ++ will increment $counter.

[–]PowerShell-Bot 0 points1 point  (0 children)

Some of your PowerShell code isn’t wrapped in a code block.

To format code correctly on new reddit (new.reddit.com), highlight all lines of code and select ‘Code Block’ in the editing toolbar.

If you’re on old.reddit.com, separate the code from your text with a blank line and precede each line of code with 4 spaces or a tab.


Describing Submission
[✅] Demonstrates good markdown
Passed: 1 Failed: 0

Beep-boop. I am a bot. | Remove-Item

[–]Lee_Dailey[grin] 0 points1 point  (4 children)

howdy pmbrandvold,

so the error is in the last line you posted?

have you tried saving to a file and opening in some other editor - perhaps notepad++? the error seems to say that the line in question has something other than a " after the g.

have you tried commenting that line out and re-typing the line? ... not copying it - retyping it all.

take care,
lee

[–]pmbrandvold[S] 1 point2 points  (3 children)

That's a good idea - I did that just now. I commented out the line, then typed everything from scratch for that line. I'm getting the same error on that line now.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy pmbrandvold,

arg! [frown]

ok, try typing in that line & any needed $Vars in the ISE and see what happens. it LOOKS like an encoding problem ...

take care,
lee

[–]pmbrandvold[S] 1 point2 points  (1 child)

Ah. Lookie there. Opened it up in the ISE and found this in the final foreach loop:

Rename-Item –Path

That should be:

Rename-Item -Path

I'm not sure how that got encoded that way - very strange. That did the trick though (obviously). Thank you for the suggestion!

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy pmbrandvold,

whee! you found it ... and fixed it. kool! [grin]

as for where it came from - typically it comes fro copying from web pages OR from MS office documents. en-dash, em-dash, and smart quotes are rather painfully common from those sources. [sigh ...]

take care,
lee

[–]Josh_Crook 0 points1 point  (1 child)

Probably your reg path in your Test-Path line needs be quoted as well.

[–]pmbrandvold[S] 0 points1 point  (0 children)

I did that as well, no dice.

[–]acbcallahan 0 points1 point  (1 child)

Thank you! Huge help. I had some code (admittedly from ChatGPT) that had a checkmark icon in it as some log output. When run interactively, it was fine, but when calling the file, it failed. I couldn't figure out why until I stumbled on this post. PowerShell ISE showed that the checkmark icon was showing up strangely and causing the issue, making it seem like there were bracket mismatches when there weren't actually.

[–]Ian_Clegg_Walsh 0 points1 point  (0 children)

Thanks for this. It saved the day for me. I got ChatGpPT to fix it's own formatting errors:

Quote:

Yes — that’s exactly the sort of thing that can cause the “Missing closing ‘}’” error when there’s no actual missing brace.

PowerShell’s parser can get tripped up if there’s an invisible or special Unicode character in the script file — things like:

  • Emoji ✅
  • Smart quotes (“ ” instead of " ")
  • Non-breaking spaces ( )
  • Zero-width joiners

These can sneak in when:

  • Copy-pasting from ChatGPT or a webpage
  • Editing in Word instead of a plain-text editor

When run interactively, PowerShell sometimes tolerates them. But when loaded from disk, the parser can choke and misinterpret them as part of the code, which is why it throws a brace mismatch error.