Skip to content

Commit b299515

Browse files
committed
Improved StartRecommendedSection function
1 parent 157c5ea commit b299515

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4634,9 +4634,9 @@ function StartRecommendedSection
46344634
$Show
46354635
)
46364636

4637-
# Windows 11 IoT Enterprise not supported
4638-
$WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%")
4639-
if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise"))
4637+
# We cannot call [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") here per this approach does not show a localized Windows edition name
4638+
# Windows 11 Home not supported
4639+
if ((Get-ComputerInfo).WindowsProductName -match "Home")
46404640
{
46414641
Write-Information -MessageData "" -InformationAction Continue
46424642
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
@@ -4657,13 +4657,20 @@ function StartRecommendedSection
46574657
{
46584658
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
46594659
}
4660+
if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education))
4661+
{
4662+
New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force
4663+
}
46604664
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force
4665+
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force
46614666

46624667
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1
46634668
}
46644669
"Show"
46654670
{
46664671
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
4672+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore
4673+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore
46674674
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR
46684675
}
46694676
}

src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,16 +4476,7 @@ function StartRecommendedSection
44764476
$Show
44774477
)
44784478

4479-
# Windows 11 IoT Enterprise not supported
4480-
$WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%")
4481-
if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise"))
4482-
{
4483-
Write-Information -MessageData "" -InformationAction Continue
4484-
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
4485-
Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
4486-
4487-
return
4488-
}
4479+
# Windows 11 IoT Enterprise is supported too. No need to check Windows edition
44894480

44904481
# Remove all policies in order to make changes visible in UI only if it's possible
44914482
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
@@ -4499,13 +4490,20 @@ function StartRecommendedSection
44994490
{
45004491
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
45014492
}
4493+
if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education))
4494+
{
4495+
New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force
4496+
}
45024497
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force
4498+
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force
45034499

45044500
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1
45054501
}
45064502
"Show"
45074503
{
45084504
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
4505+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore
4506+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore
45094507
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR
45104508
}
45114509
}

src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4652,9 +4652,9 @@ function StartRecommendedSection
46524652
$Show
46534653
)
46544654

4655-
# Windows 11 IoT Enterprise not supported
4656-
$WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%")
4657-
if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise"))
4655+
# We cannot call [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") here per this approach does not show a localized edition name
4656+
# Windows 11 Home not supported
4657+
if ((Get-ComputerInfo).WindowsProductName -match "Home")
46584658
{
46594659
Write-Information -MessageData "" -InformationAction Continue
46604660
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
@@ -4675,13 +4675,20 @@ function StartRecommendedSection
46754675
{
46764676
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
46774677
}
4678+
if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education))
4679+
{
4680+
New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force
4681+
}
46784682
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force
4683+
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force
46794684

46804685
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1
46814686
}
46824687
"Show"
46834688
{
46844689
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
4690+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore
4691+
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore
46854692
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR
46864693
}
46874694
}

0 commit comments

Comments
 (0)