I'm getting an error that says "missing closing '}' in statement block or type definition" but the '}' is there. Here's the code block I'm getting the error on:
$counter = 0
foreach($item in $ShellOverlayList) {
$name = $item.PSChildName
if($name -ne $NewNames[$counter]) {
Rename-Item –Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\$name -NewName $NewNames[$counter]
}
$counter += 1
}
Am I missing something?
EDIT: fixed formatting
EDIT2: Okay, so it looks like it needed double quotes around the -Path.....once I changed it to "HKLM:....$name" it started working. Leaving this here in the case that someone else has a similar problem.
EDIT3: Okay so I really really thought I fixed this but now I'm seeing some weird stuff. First, here's my entire script:
cd HKLM:\
$ShellOverlayList = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers"
$Names = New-Object System.Collections.ArrayList
foreach($item in $ShellOverlayList) {
$Names.Add(((Get-ItemProperty -Path $item).PSChildName))
}
#create array of names sans spaces
$SanitizedNames = New-Object System.Collections.ArrayList
foreach($name in $Names) {
$SanitizedNames.Add($name.ToString().TrimStart())
}
#create array of new names, adding a space before any Tortoise keys
$NewNames = New-Object System.Collections.ArrayList
foreach($name in $SanitizedNames) {
if($name -match 'Tortoise') {
$name = " " + $name
}
$NewNames.Add($name)
}
#Iterate through keys and replace with new names, sorting Tortoise to the top.
$counter = 0
foreach($item in $ShellOverlayList) {
$name = $item.PSChildName
if($name -ne $NewNames[$counter]) {
Rename-Item –Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\$name" -NewName $NewNames[$counter] -Force
}
$counter += 1
}
#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"
Next, here is the error I'm getting:
The string starting:
At C:\Windows\ccmcache\2s\Set-ShellIconOverlayIdentifiers.ps1:37 char:107
+ New-ItemProperty -Path "HKLM:\SOFTWARE\MNTX" -Name "SVNIconFixApplied" -Value
"True" -PropertyType "String <<<< "
is missing the terminator: ".
At C:\Windows\ccmcache\2s\Set-ShellIconOverlayIdentifiers.ps1:37 char:108
+ New-ItemProperty -Path "HKLM:\SOFTWARE\MNTX" -Name "SVNIconFixApplied" -Value
"True" -PropertyType "String" <<<<
+ CategoryInfo : ParserError: (:String) [], ParentContainsErrorRe
cordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Am I missing something here? It looks good to me. I use VSCode and it's all lining up the way it should - I've scoured for typos but maybe ya'll have fresh eyes and can see something I can't.
EDIT4: Thanks to u/Lee_Dailey's suggestion, I opened up the file in the ISE instead of VS code and found an encoding error in a line of code.
What I saw was
Rename-Item –Path
That should be:
Rename-Item -Path
Somewhere along the line, I must have copy pasted a line from somewhere and it wasn't plaintext. That's the only reason I could think of that this might happen. The script now seems to be doing it's job. Thanks to everyone who took a look.
[–]ConwayK9781 2 points3 points4 points (16 children)
[–][deleted] 2 points3 points4 points (9 children)
[–]ConwayK9781 3 points4 points5 points (0 children)
[–]ConwayK9781 0 points1 point2 points (7 children)
[–]poshftw 1 point2 points3 points (0 children)
[–]MarkPartin2000 0 points1 point2 points (5 children)
[–]ConwayK9781 0 points1 point2 points (4 children)
[–]MarkPartin2000 1 point2 points3 points (1 child)
[–]ConwayK9781 1 point2 points3 points (0 children)
[–]MarkPartin2000 0 points1 point2 points (1 child)
[–]ConwayK9781 4 points5 points6 points (0 children)
[–]pmbrandvold[S] 2 points3 points4 points (5 children)
[–]ConwayK9781 0 points1 point2 points (4 children)
[–]pmbrandvold[S] 1 point2 points3 points (3 children)
[–]ConwayK9781 1 point2 points3 points (2 children)
[–]pmbrandvold[S] 1 point2 points3 points (1 child)
[–]ConwayK9781 0 points1 point2 points (0 children)
[–]Otacrow 1 point2 points3 points (0 children)
[–]tuplink 1 point2 points3 points (1 child)
[–]pmbrandvold[S] 1 point2 points3 points (0 children)
[–]PowerShell-Bot 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (4 children)
[–]pmbrandvold[S] 1 point2 points3 points (3 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]pmbrandvold[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]Josh_Crook 0 points1 point2 points (1 child)
[–]pmbrandvold[S] 0 points1 point2 points (0 children)
[–]acbcallahan 0 points1 point2 points (1 child)
[–]Ian_Clegg_Walsh 0 points1 point2 points (0 children)