From f87837576609524866e497cf1f5c36f51c89d835 Mon Sep 17 00:00:00 2001
From: farag2 <farag2@users.noreply.github.com>
Date: Fri, 21 Jun 2019 14:23:42 +0300
Subject: [PATCH] 21.06.2019
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Added clearing $Error variable at the beginning of the script;
Added check for the presence of a file when adding folder to exclude from Windows Defender Antivirus scan;
Fixed typo in "Show "Explorer" and "Settings" folders on Start menu" section;

В начале скрипта добавлена очистка переменной $Error;
Добавлена проверка на наличие файла при добавлении папки в список исключений сканирования Защитника Windows;
Исправлена опечатка в разделе "Отобразить папки "Проводник" и "Параметры" в меню "Пуск"".
---
 Win 10.ps1 | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/Win 10.ps1 b/Win 10.ps1
index 7d422244..53365436 100644
--- a/Win 10.ps1	
+++ b/Win 10.ps1	
@@ -1,3 +1,6 @@
+# Сlear $Error
+# Очистка $Error
+$Error.Clear()
 # Turn off diagnostics tracking services
 # Отключить службы диагностического отслеживания
 $services = @(
@@ -490,7 +493,6 @@ Remove-Item -Path $env:USERPROFILE\OneDrive -Recurse -Force -ErrorAction Silentl
 Remove-Item -Path $env:LOCALAPPDATA\Microsoft\OneDrive -Recurse -Force -ErrorAction SilentlyContinue
 Remove-Item -Path "$env:ProgramData\Microsoft OneDrive" -Recurse -Force -ErrorAction SilentlyContinue
 Unregister-ScheduledTask -TaskName *OneDrive* -Confirm:$false
-Remove-Item -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force -ErrorAction SilentlyContinue
 # Turn on updates for other Microsoft products
 # Включить автоматическое обновление для других продуктов Microsoft
 (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
@@ -636,7 +638,10 @@ function Get-ResolvedPath
 	(Get-Disk | Where-Object -FilterScript {$_.IsBoot -eq $false} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | ForEach-Object -Process {Join-Path ($_ + ":") $Path -Resolve -ErrorAction SilentlyContinue}
 }
 $folder = "Программы\Прочее" | Get-ResolvedPath -ErrorAction SilentlyContinue
-Add-MpPreference -ExclusionPath $folder -Force
+IF ($folder)
+{
+	Add-MpPreference -ExclusionPath $folder -Force
+}
 # Turn on Windows Defender Exploit Guard Network Protection
 # Включить Защиту сети в Защитнике Windows
 Set-MpPreference -EnableNetworkProtection Enabled
@@ -740,12 +745,13 @@ Clear-ItemProperty -Path "HKLM:\SOFTWARE\Classes\Folder\shellex\ContextMenuHandl
 IF (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -eq "Professional" -or $_.Edition -eq "Enterprise"})
 {
 	$keys = @(
-	"encrypt-bde",
-	"encrypt-bde-elev",
-	"manage-bde",
-	"resume-bde",
-	"resume-bde-elev",
-	"unlock-bde")
+		"encrypt-bde",
+		"encrypt-bde-elev",
+		"manage-bde",
+		"resume-bde",
+		"resume-bde-elev",
+		"unlock-bde"
+	)
 	Foreach ($key in $keys)
 	{
 		New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\$key -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
@@ -912,8 +918,8 @@ Else
 	# Show "Explorer" and "Settings" folders on Start menu
 	# Отобразить папки "Проводник" и "Параметры" в меню "Пуск"
 	$items = @("Проводник", "Параметры")
-	$key = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount\*windows.data.unifiedtile.startglobalproperties\Current"
-	$data = $key.Data[0..19] -join ","
+	$key2 = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount\*windows.data.unifiedtile.startglobalproperties\Current"
+	$data = $key2.Data[0..19] -join ","
 	$data += ",203,50,10,$($items.Length)"
 	# Explorer
 	# Проводник
@@ -922,7 +928,7 @@ Else
 	# Параметры
 	$data += ",5,134,145,204,147,5,36,170,163,1,68,195,132,1,102,159,247,157,177,135,203,209,172,212,1,0"
 	$data += ",194,60,1,194,70,1,197,90,1,0"
-	New-ItemProperty -Path $key.PSPath -Name Data -PropertyType Binary -Value $data.Split(",") -Force
+	New-ItemProperty -Path $key2.PSPath -Name Data -PropertyType Binary -Value $data.Split(",") -Force
 }
 # Show accent color on the title bars and window borders
 # Отображать цвет элементов в заголовках окон и границ окон