diff --git a/Win 10.ps1 b/Win 10.ps1 index 342a0a90..81073c4c 100644 --- a/Win 10.ps1 +++ b/Win 10.ps1 @@ -20,8 +20,8 @@ .EXAMPLE PS C:\> & '.\Win 10.ps1' .NOTES - Version: v4.2 - Date: 12.05.2020 + Version: v4.2.1 + Date: 16.05.2020 Written by: farag Thanks to all http://forum.ru-board.com members involved Ask a question on @@ -922,6 +922,7 @@ Disable-WindowsOptionalFeature -Online -FeatureName $WindowsOptionalFeatures -No # Удалить дополнительные компоненты Windows Add-Type -AssemblyName PresentationCore, PresentationFramework +#region Variables # Windows capabilities array list to remove # Массив имен дополнительных компонентов Windows для удаления $Capabilities = New-Object System.Collections.ArrayList($null) @@ -945,6 +946,25 @@ if ((Get-CimInstance -ClassName Win32_ComputerSystem).PCSystemType -ne 2) # Распознавание лиц Windows Hello $CheckedCapabilities += "Hello.Face*" } +# Windows capabilities that will be shown in the GUI +# Дополнительные компоненты Windows, которые будут выводиться в GUI +$ExcludedCapabilities = @( + # The DirectX Database to configure and optimize apps when multiple Graphics Adapters are present + # База данных DirectX для настройки и оптимизации приложений при наличии нескольких графических адаптеров + "DirectX\.Configuration\.Database" + # Language components + # Языковые компоненты + "Language\." + # Mail, contacts, and calendar sync component + # Компонент синхронизации почты, контактов и календаря. + "OneCoreUAP\.OneSync" + # Management of printers, printer drivers, and printer servers + # Управление принтерами, драйверами принтеров и принт-серверами + "Print\.Management\.Console" + # Features critical to Windows functionality + # Компоненты, критичные для работоспособности Windows + "Windows\.Client\.ShellComponents" +) #endregion Variables #region XAML Markup @@ -952,7 +972,7 @@ if ((Get-CimInstance -ClassName Win32_ComputerSystem).PCSystemType -ne 2) Add-Type -AssemblyName PresentationCore, PresentationFramework @@ -2101,6 +2126,19 @@ $UncheckedAppxPackages = @( # Realtek Audio Console "RealtekSemiconductorCorp.RealtekAudioControl" ) + +# UWP-apps that won't be shown in the form +# UWP-приложения, которые не будут выводиться в форме +$ExcludedAppxPackages = @( + # Microsoft Desktop App Installer + "Microsoft.DesktopAppInstaller" + # Microsoft Store + "Microsoft.StorePurchaseApp" + "Microsoft.WindowsStore" + # Web Media Extensions + # Расширения для интернет-мультимедиа + "Microsoft.WebMediaExtensions" +) #endregion Variables #region XAML Markup @@ -2146,9 +2184,9 @@ $UncheckedAppxPackages = @( #endregion XAML Markup $Reader = (New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML) -$GUI = [Windows.Markup.XamlReader]::Load($Reader) +$Form = [Windows.Markup.XamlReader]::Load($Reader) $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $GUI.FindName($_.Name) -Scope Global + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) -Scope Global } #region Functions @@ -2235,18 +2273,6 @@ function Add-AppxControl #region Events Handlers # Window Loaded Event $Window.Add_Loaded({ - # UWP-apps that won't be shown in the form - # UWP-приложения, которые не будут выводиться в форме - $ExcludedAppxPackages = @( - # Microsoft Desktop App Installer - "Microsoft.DesktopAppInstaller" - # Microsoft Store - "Microsoft.StorePurchaseApp" - "Microsoft.WindowsStore" - # Web Media Extensions - # Расширения для интернет-мультимедиа - "Microsoft.WebMediaExtensions" - ) $OFS = "|" (Get-AppxPackage -PackageTypeFilter Bundle -AllUsers | Where-Object -FilterScript {$_.Name -cnotmatch $ExcludedAppxPackages}).Name | ForEach-Object -Process { Add-AppxControl -AppxName $_ @@ -2258,15 +2284,31 @@ $Window.Add_Loaded({ $Button.Add_Click({DeleteButton}) #endregion Events Handlers -if ($RU) +if (Get-AppxPackage -PackageTypeFilter Bundle -AllUsers | Where-Object -FilterScript {$_.Name -cnotmatch ($ExcludedAppxPackages -join "|")}) { - Write-Verbose -Message "GUI открывается..." -Verbose + if ($RU) + { + Write-Verbose -Message "Форма открывается..." -Verbose + } + else + { + Write-Verbose "Form opening..." -Verbose + } + # Display form + # Display форму + $Form.ShowDialog() | Out-Null } else { - Write-Verbose "GUI opening..." -Verbose + if ($RU) + { + Write-Verbose -Message "No UWP apps to display" -Verbose + } + else + { + Write-Verbose "Отсутствуют UWP-приложения для отображения" -Verbose + } } -$GUI.ShowDialog() | Out-Null <# Open Microsoft Store "HEVC Video Extensions from Device Manufacturer" page @@ -2371,6 +2413,7 @@ if (Get-CimInstance -ClassName Win32_VideoController | Where-Object -FilterScrip { New-ItemProperty -Path HKCU:\Software\Microsoft\DirectX\UserGpuPreferences -Name $OpenFileDialog.FileName -PropertyType String -Value "GpuPreference=2;" -Force } + $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice) } "1" { @@ -2544,18 +2587,27 @@ $Process.Start() | Out-Null ' $EncodedScript = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($PS1Script)) -$action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -EncodedCommand $EncodedScript" -$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9am -$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest -$params = @{ - "TaskName" = "Update Cleanup" - "Action" = $action - "Trigger" = $trigger - "Settings" = $settings - "Principal" = $principal +$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -EncodedCommand $EncodedScript" +$Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9am +$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable +$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest +if ($RU) +{ + $Description = "Очистка неиспользуемых обновлений Windows и прочих ненужных файлов, используя встроенную программу 'Очистка диска'" +} +else +{ + $Description = "Cleaning up unused Windows Update files and other unnecessary files using built-in 'Disk cleanup'" +} +$Parameters = @{ + "Action" = $Action + "Trigger" = $Trigger + "Settings" = $Settings + "Principal" = $Principal + "Description" = $Description + "TaskName" = "Update Cleanup" } -Register-ScheduledTask @params -Force +Register-ScheduledTask @Parameters -Force <# Create a task in the Task Scheduler to clear the %SystemRoot%\SoftwareDistribution\Download folder @@ -2567,18 +2619,27 @@ $Argument = " (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') Get-ChildItem -Path $env:SystemRoot\SoftwareDistribution\Download -Recurse -Force | Remove-Item -Recurse -Force " -$action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument -$trigger = New-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Thursday -At 9am -$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest -$params = @{ - "TaskName" = "SoftwareDistribution" - "Action" = $action - "Trigger" = $trigger - "Settings" = $settings - "Principal" = $principal -} -Register-ScheduledTask @params -Force +$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument +$Trigger = New-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Thursday -At 9am +$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable +$Principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest +if ($RU) +{ + $Description = "Очистка папки %SystemRoot%\SoftwareDistribution\Download" +} +else +{ + $Description = "The %SystemRoot%\SoftwareDistribution\Download folder cleaning" +} +$Parameters = @{ + "Action" = $Action + "Trigger" = $Trigger + "Settings" = $Settings + "Principal" = $Principal + "Description" = $Description + "TaskName" = "SoftwareDistribution" +} +Register-ScheduledTask @Parameters -Force <# Create a task in the Task Scheduler to clear the %TEMP% folder @@ -2587,18 +2648,27 @@ The task runs every 62 days Задача выполняется каждые 62 дня #> $Argument = "Get-ChildItem -Path $env:TEMP -Force -Recurse | Remove-Item -Force -Recurse" -$action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument -$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 62 -At 9am -$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest -$params = @{ - "TaskName" = "Temp" - "Action" = $action - "Trigger" = $trigger - "Settings" = $settings - "Principal" = $principal -} -Register-ScheduledTask @params -Force +$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument +$Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 62 -At 9am +$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable +$Principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest +if ($RU) +{ + $Description = "Очистка папки %TEMP%" +} +else +{ + $Description = "The %TEMP% folder cleaning" +} +$Parameters = @{ + "Action" = $Action + "Trigger" = $Trigger + "Settings" = $Settings + "Principal" = $Principal + "Description" = $Description + "TaskName" = "Temp" +} +Register-ScheduledTask @Parameters -Force #endregion Scheduled tasks #region Windows Defender & Security @@ -2854,7 +2924,7 @@ auditpol /set /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /success:ena # Include command line in process creation events # Включать командную строку в событиях создания процесса -$ProcessCreation = auditpol /get /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /r | ConvertFrom-Csv | Select-Object "Inclusion Setting" +$ProcessCreation = auditpol /get /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /r | ConvertFrom-Csv | Select-Object -ExpandProperty "Inclusion Setting" if ($ProcessCreation."Inclusion Setting" -ne "No Auditing") { New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -PropertyType DWord -Value 1 -Force @@ -3103,4 +3173,4 @@ else Write-Host "`nNo warnings/errors" -ForegroundColor Green } } -#endregion End +#endregion End \ No newline at end of file