Tôi cũng hỏi bạn đã chạy những tập lệnh nào.
Nhưng có một điều tôi gặp phải trên hai máy tính của mình trong tuần này là tôi đã cài bản cập nhật 22H2 trên máy tính chạy Windows 10 và mọi thứ đều ổn. Cho đến ngày hôm sau khi bật PC lên thì cài đặt Windows 10 bị lỗi?
Đã cài Windows 11 và mọi thứ ổn thỏa.
Không biết bạn có nhận được bản cập nhật không
Đã gần một tháng kể từ khi tôi chạy tập lệnh (hoặc 2 tháng), nhưng tôi tìm thấy một số tập lệnh từ lịch sử trình duyệt của mình. Tôi nghi ngờ tập lệnh này:
##_Lấy tổng dung lượng đĩa khả dụng trước khi bắt đầu dọn dẹp
$diskBefore = (Get-WmiObject Win32_LogicalDisk).FreeSpace | Measure-Object -Sum
$before = [math]::Round($diskBefore.Sum/1MB,2)
Write-Host "Sử dụng đĩa bắt đầu: $before MB"
##_Dọn dẹp đĩa
##_Tạo khóa reg
if (!(Test-Path("HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files"))) { New-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" -Force | New-ItemProperty -Name 'LastAccess' -Value '2' -Force | Out-Null; } else { Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" | New-ItemProperty -Tên 'LastAccess' -Giá trị '2' -Buộc | Out-Null;}
$regKeys = @(
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thư mục tạm thời thiết lập đang hoạt động",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp chương trình đã tải xuống",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp bộ nhớ đệm Internet",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp đổ bộ nhớ",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Tệp",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Cài đặt trước",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Thùng rác",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Nội dung ngoại tuyến của RetailDemo",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Dọn dẹp gói dịch vụ",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Tệp nhật ký thiết lập",
"HKLM

HẦN MỀM\Microsoft\Windows\Phiên bản hiện tại\Explorer\VolumeCaches\Tệp đổ bộ nhớ lỗi hệ thống",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp lỗi hệ thống",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp tạm thời",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp thiết lập tạm thời",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Bộ nhớ đệm hình thu nhỏ",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Dọn dẹp bản cập nhật",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Nâng cấp các tệp đã hủy",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Defender",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Files",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp cài đặt Windows ESD",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp nhật ký đặt lại Windows",
"HKLM

HẦN MỀM\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp nhật ký nâng cấp Windows")
foreach($key in $regKeys){
if (!(Test-Path("$key"))) { Mục mới "$key" -Force | Thuộc tính mục mới -Tên 'StateFlags0420' -Giá trị '2' -Force | Out-Null; } else { Get-Item "$key" | Thuộc tính mục mới -Tên 'StateFlags0420' -Giá trị '2' -Force | Out-Null;}
}
##_Chạy dọn dẹp đĩa
Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList "/sagerun:420"
##_Xóa thư mục Temp
##Remove-Item -Path $env:TEMP* -Recurse -Force
##System Temp
$systemTempPath = Join-Path -Path $env:windir -ChildPath '\Temp'
Get-ChildItem -Path $systemTempPath | Where-Object { $.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Recurse -Force -Confirm:$false
##_User Temp
$userProfiles = Get-ChildItem -Path C:\Users -Directory
##_Lặp qua từng hồ sơ người dùng
foreach ($userProfile in $userProfiles) {
$userName = $userProfile.Name
$tempFolderPath = Join-Path -Path $userProfile.FullName -ChildPath 'AppData\Local\Temp'
##_Kiểm tra xem thư mục "\AppData\Local\Temp" có tồn tại đối với người dùng không
if (Test-Path -Path $tempFolderPath -PathType Container) {
##_Dọn dẹp tất cả các tệp trong "\AppData\Local\Temp" đối với người dùng cũ hơn 30 ngày
Get-ChildItem -Path $tempFolderPath | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Recurse -Force -Confirm:$false
} else {
Write-Host "Không tìm thấy thư mục Temp nào cho $userName."
}
}
##_Xóa ứng dụng Windows rác
##_Liệt kê các gói
##_Get-AppxPackage -AllUsers | Chọn tên, PackageFullName
get-appxpackage -AllUsers *BingNews* | remove-appxpackage -AllUsers
get-appxpackage -AllUsers *WindowsMaps* | remove-appxpackage -AllUsers
get-appxpackage -AllUsers *YourPhone* | remove-appxpackage -AllUsers
get-appxpackage -AllUsers *xboxapp* | remove-appxpackage -AllUsers
get-appxpackage -AllUsers *Microsoft.XboxApp* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *Microsoft.Xbox.* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *XboxGamingOverlay* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *XboxIdentityProvider* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *XboxSpeechToTextOverlay* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *SkypeApp* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *XboxOneSmartGlass* | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng Microsoft.windowscommunicationsapps | remove-appxpackage -Tất cả người dùng
get-appxpackage -Tất cả người dùng *ZuneMusic* | remove-appxpackage -AllUsers
get-appxpackage -AllUsers *ZuneVideo* | remove-appxpackage -AllUsers
##_Làm trống Thùng rác
$driveName = (Get-ChildItem -Path Env:\SystemDrive).Value
Remove-Item -Path $driveName`$recycle.bin -Recurse -Force -Confirm:$false
##_Dọn dẹp các gói hệ thống (C:\Windows\WinSxS)
#dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
##_Lấy dung lượng khả dụng của tất cả các ổ đĩa sau khi dọn dẹp
$diskAfter = (Get-WmiObject Win32_LogicalDisk).FreeSpace | Measure-Object -Sum
##_Sử dụng các giá trị từ tổng dung lượng đĩa được sử dụng trước và sau tập lệnh này để tính toán
##_tổng dung lượng đã tiết kiệm, sau đó chuyển đổi thành MB để dễ đọc hơn
$after = [math]::Round($diskAfter.Sum/1MB,2)
$saved = [math]::Round(($before - $after),2)
$savedGBs = [math]::Round(($saved * 1024 * 1024 / 1GB),2)
##_Nếu dung lượng ít hơn trước khi tập lệnh bắt đầu, chỉ cần báo cáo lại 0
If($saved -gt 0) {
$saved = 0
}
##_Định dạng đầu ra để chúng ta có thể chia các biến
Write-Output "before=$before|after=$after|spaceSaved=$($saved)MBs|spaceSavedGBs=$($savedGBs)GBs"
Write-Host "Kết thúc sử dụng đĩa: $after MB"
Write-Host "Kết thúc lưu: $saved MB"
Thoát 0
Và lệnh thứ hai có thể là:
Tập lệnh này sẽ chỉ chạy mà không có bất kỳ lời nhắc nào, vì vậy hãy đảm bảo rằng bạn đã kiểm tra và hài lòng với nó trước khi chạy trên hệ thống trực tiếp. Bạn luôn có thể chỉ cần bình luận những gì bạn không muốn, chẳng hạn như nhật ký sự kiện.
========================================================================================================
Lưu tệp này dưới dạng "Windows_Cleanup.cmd" (Tệp hàng loạt)
powershell.exe -ExecutionPolicy Bypass -File "%~dp0\Windows_Cleanup.ps1"
pause
= ...
Lưu tệp này dưới dạng "Windows_Cleanup.PS1" (Power shell Script)
# Được viết bởi Fabian Castagna
# Được sử dụng như một công cụ dọn dẹp windows hoàn chỉnh
# 15-7-2016
function Delete-ComputerRestorePoints{
[CmdletBinding(SupportsShouldProcess=$True)]param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true
)]
$restorePoints
)
begin{
$fullName="SystemRestore.DeleteRestorePoint"
#kiểm tra xem kiểu đã được tải chưa
$isLoaded=([AppDomain]::CurrentDomain.GetAssemblies() | foreach {$_.GetTypes()} | where {$_.FullName -eq $fullName}) -ne $null
if (!$isLoaded){
$SRClient= Add-Type -memberDefinition @"
[DllImport ("Srclient.dll")]
public static extern int SRRemoveRestorePoint (int index);
"@ -Name DeleteRestorePoint -NameSpace SystemRestore -PassThru
}
}
process{
foreach ($restorePoint in $restorePoints){
if($PSCmdlet.ShouldProcess("$($restorePoint.Description)","Đang xóa điểm khôi phục")) {
[SystemRestore.DeleteRestorePoint]::SRRemoveRestorePoint($restorePoint.SequenceNumber)
}
}
}
}
Write-Host "Đang xóa điểm khôi phục hệ thống"
Get-ComputerRestorePoint | Xóa-ComputerRestorePoints # -WhatIf
Write-host "Đang kiểm tra để đảm bảo bạn có quyền Quản trị viên cục bộ" -foreground yellow
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "Vui lòng chạy tập lệnh này với tư cách là Quản trị viên!"
If (!($psISE)){"Nhấn phím bất kỳ để tiếp tục…";[void][System.Console]::ReadKey($true)}
Thoát 1
}
Write-Host "Thu thập dung lượng đĩa trống hiện tại trên Ổ đĩa C" -foreground yellow
$FreespaceBefore = (Get-WmiObject win32_logicaldisk -filter "DeviceID='C:'" | select Freespace).FreeSpace/1GB
Write-host "Đang xóa Thư mục Rouge" -foreground yellow
if (test-path C:\Config.Msi) {remove-item -Path C:\Config.Msi -force -recurse}
if (test-path c:\Intel) {remove-item -Path c:\Intel -force -recurse}
if (test-path c:\PerfLogs) {remove-item -Path c:\PerfLogs -force -recurse}
# if (test-path c:\swsetup) {remove-item -Path c:\swsetup -force -recurse} # Kho lưu trữ phần mềm và trình điều khiển HP
if (test-path $env:windir\memory.dmp) {remove-item $env:windir\memory.dmp -force}
Write-host "Đang xóa tệp báo cáo lỗi của Windows" -foreground yellow
if (test-path C:\ProgramData\Microsoft\Windows\WER) {Get-ChildItem -Đường dẫn C:\ProgramData\Microsoft\Windows\WER -Đệ quy | Remove-Item -force -recurse}
Write-host "Đang xóa các tệp tạm thời của hệ thống và người dùng" -foreground yellow
Remove-Item -Path "$env:windir\Temp\*" -Force -Recurse
Remove-Item -Path "$env:windir\minidump\*" -Force -Recurse
Remove-Item -Path "$env:windir\Prefetch\*" -Force -Recurse
Remove-Item -Path "C:\Users\*\AppData\Local\Temp\*" -Force -Recurse
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\WER\*" -Force -Recurse
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Force -Recurse
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatCache\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatUaCache\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatUaCache\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Windows\IEDownloadHistory\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\*" -Buộc -Đệ trình
Xóa-Mục -Đường dẫn "C:\Users\*\AppData\Local\Microsoft\Terminal Server Client\Cache\*" -Buộc -Recurse
Write-host "Đang xóa các bản tải xuống của Windows Updates" -foreground yellow
Stop-Service wuauserv -Force -Verbose
Stop-Service TrustedInstaller -Force -Verbose
Remove-Item -Path "$env:windir\SoftwareDistribution\*" -Force -Recurse
Remove-Item $env:windir\Logs\CBS\* -force -recurse
Start-Service wuauserv -Verbose
Start-Service TrustedInstaller -Verbose
Write-host "Kiểm tra xem Windows Cleanup có tồn tại không" -foreground yellow
#Chủ yếu dành cho máy chủ 2008
if (!(Test-Path c:\windows\System32\cleanmgr.exe)) {
Write-host "Windows Cleanup KHÔNG được cài đặt, hiện đang cài đặt" -foreground yellow
copy-item $env:windir\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe $env:windir\System32
copy-item $env:windir\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui $env:windir\System32\en-US
}
Write-host "Đang chạy Dọn dẹp hệ thống Windows" -foreground yellow
#Đặt cài đặt StateFlags cho từng mục trong dọn dẹp đĩa Windows tiện ích
$StateFlags = 'StateFlags0013'
$StateRun = $StateFlags.Substring($StateFlags.get_Length()-2)
$StateRun = '/sagerun:' + $StateRun
if (-not (get-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders' -name $StateFlags)) {
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Service Pack Cleanup' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp dump bộ nhớ lỗi hệ thống' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp dump lỗi hệ thống' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp tạm thời' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Tệp thiết lập tạm thời' -name $StateFlags -type DWORD -Giá trị 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\User file versions' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Defender' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Temp Files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows ESD installation files' -name $StateFlags -type DWORD -Value 2
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files' -name $StateFlags -type DWORD -Value 2
}
Write-host "Đang bắt đầu CleanMgr.exe.." -foreground yellow
Start-Process -FilePath CleanMgr.exe -ArgumentList $StateRun -WindowStyle Hidden -Wait
Write-host "Đang xóa tất cả nhật ký sự kiện" -foreground yellow
wevtutil el | Foreach-Object {Write-Host "Đang xóa $_"; wevtutil cl "$_"}
Write-host "Sử dụng đĩa trước và sau khi dọn dẹp" -foreground yellow
$FreespaceAfter = (Get-WmiObject win32_logicaldisk -filter "DeviceID='C:'" | select Freespace).FreeSpace/1GB
"Dung lượng trống trước: {0}" -f $FreespaceBefore
"Dung lượng trống sau: {0}" -f $FreespaceAfter
Tôi đang tìm kiếm xem có tập lệnh nào khác trông quen thuộc có thể là tập lệnh đó không.
Tôi đã thử chuyển từ bios hiện tại sang bios gốc bằng cách bật công tắc trên bo mạch chủ và khởi động máy tính, nhưng không có tác dụng.